---
# System prepended metadata

title: 11270 - reverse linked list
tags: [csst]

---

# 11270 - reverse linked list

> author: atsushi
###### tags: `csst`

---


## Solution 1
 
### 想法：
- 因為李哲榮教授上一次上課講了許多recursion，這次create就用recursion做，只是reverse在下實在想不到有什麼recursion的寫法。期待樓下大大更新。

```c

#include <stdio.h>
#include <stdlib.h>
#include "function.h"
Node* createList(){
    int d;
    Node * head = NULL;
    Node * tmp = NULL;
    if(~scanf("%d", &d)){
        // printf("get%d!\n",d);
        if(d == -1)
            return NULL;
        head = (Node*) malloc(sizeof(Node));
        head->data = d;
        head->next = createList();
   }
    return head;
}
Node* reverse(Node* head){
    Node* previous = NULL;
    Node* current = head;
    Node* success;
    while(current->next != NULL){
        success = current->next;
        current->next = previous;
        previous = current;
        current = success;
    }
    current->next = previous;
    head = current;    
    return head;
}
// By atsushi
```

```

## Reference