Created
May 14, 2012 01:14
-
-
Save underhilllabs/2691116 to your computer and use it in GitHub Desktop.
Exchange Nodes in a linked list
This file contains hidden or 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
/* Exchange places of nodes after, the nodes passed in.*/ | |
exchange(struct node *u, struct node *v) { | |
struct node *x, *y; | |
x = u->next; | |
u->next = u->next->next; | |
y = v->next; | |
v->next = v->next->next; | |
y->next = u->next; | |
u->next = y; | |
x->next = v->next; | |
v->next = x; | |
} | |
struct node { | |
int key; | |
struct node *next; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment