Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Created May 14, 2012 01:14
Show Gist options
  • Save underhilllabs/2691116 to your computer and use it in GitHub Desktop.
Save underhilllabs/2691116 to your computer and use it in GitHub Desktop.
Exchange Nodes in a linked list
/* 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