Last active
August 29, 2015 14:07
-
-
Save clinyong/a565c64fe26e9ab13c15 to your computer and use it in GitHub Desktop.
单链表反向
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct node{ | |
int val; | |
struct node *next; | |
}node; | |
void reverse(node *currentNode) | |
{ | |
node *preNode = NULL; | |
node *nextNode = NULL; | |
while(currentNode) { | |
//save the next node | |
nextNode = currentNode->next; | |
//update the value of "next" | |
currentNode->next = preNode; | |
//shift the pointers | |
preNode = currentNode; | |
currentNode = nextNode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment