#include<stdio.h>typedefstructLINK{int data;structLINK*next;}Link;voidprintLink(Link*head){while( head !=NULL){printf("%d ->",head->data);
head = head->next;}printf("NULL\n");}
Link*reverseLink(Link *head){
Link *pre =NULL;
Link *cur = head;
Link *back;while(cur){
back = cur->next;
cur->next = pre;
pre = cur;
cur = back;}
head->next =NULL;return pre;}intmain(){
Link node4 ={4,NULL};
Link node3 ={3,&node4};
Link node2 ={2,&node3};
Link node1 ={1,&node2};
Link *head =NULL;printf("Sourse LinkTab:\n");printLink(&node1);printf("reverse LinkTab:\n");
head =reverseLink(&node1);printLink(head);return0;}
递归
#include<stdio.h>typedefstructLINK{int data;structLINK*next;}Link;voidprintLink(Link*head){while( head !=NULL){printf("%d ->",head->data);
head = head->next;}printf("NULL\n");}
Link*reverseLink(Link *head){if(head ==NULL|| head->next ==NULL){return head;}
Link* newHead =reverseLink(head->next);
head->next->next = head;
head->next =NULL;return newHead;}intmain(){
Link node4 ={4,NULL};
Link node3 ={3,&node4};
Link node2 ={2,&node3};
Link node1 ={1,&node2};
Link *head =NULL;printf("Sourse LinkTab:\n");printLink(&node1);printf("reverse LinkTab:\n");
head =reverseLink(&node1);printLink(head);return0;}