---
# System prepended metadata

title: 11315 - Reverse Linked List
tags: [NTHUOJ]

---

# 11315 - Reverse Linked List
## 題解:
視作為push front來建立一個linked list就好了
## Code:
```cpp
#include "function.h"
#include <stdio.h>
#include <stdlib.h>

Node* createReversedList(){
    int val;
    Node* head = NULL;
    while(1){
        scanf("%d", &val);
        if(val == -1) break;
        // create new node
        Node* new_node = (Node*)malloc(sizeof(Node));
        new_node->data = val;
        // push front
        new_node->next = head;
        head = new_node;
    }
    return head;
}
```
###### tags: `NTHUOJ`