#include <stdio.h> typedef struct node { int val; node* next; }; node* reverse(node* list , node* &head) { if ( !list || !list->next ) { head->next = NULL; head = list; return list; } else { node* temp = reverse( list->next , head); temp->next = list; return list; } } node* nonreverse(node* head) { node* p1,*p2,*temp; p1 = head; if (p1) p2 = p1->next ; while ( p2) { temp = p2->next ; p2->next = p1; p1 = p2; p2 = temp; } head->next = NULL; head = p1; return head; } node* create(int n ) { int i ; node* head ; node* temp ,*pre; head = NULL; head = new node; pre = head; while ( n --) { temp = new node; scanf("%d" , &temp->val); pre ->next= temp ; pre = temp; } pre->next = NULL; return head->next; } int main() { node* list1,*list2; list1 = create(5); //list2= reverse(list1, list1); list2 = nonreverse(list1); return 0 ; }