Skip to content

Instantly share code, notes, and snippets.

@clinyong
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clinyong/a565c64fe26e9ab13c15 to your computer and use it in GitHub Desktop.
Save clinyong/a565c64fe26e9ab13c15 to your computer and use it in GitHub Desktop.
单链表反向
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