Skip to content

Instantly share code, notes, and snippets.

@berkayk
Created January 29, 2016 10:04
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 berkayk/c20694faeea42e986bc4 to your computer and use it in GitHub Desktop.
Save berkayk/c20694faeea42e986bc4 to your computer and use it in GitHub Desktop.
public void partitionList(Node head, int value) {
Node small = null;
Node smallItr = null;
Node great = null;
Node greatItr;
while (head != null) {
if (head.data < value) {
if (smallItr == null) {
small = smallItr = head;
}
else {
// Add in between so we don't lose head
smallItr.next = head;
smallItr = smallItr.next;
}
}
else {
// greater than or equal
if (greatItr == null) {
great = greatItr = head;
}
else {
greatItr.next = head;
greatItr = greatItr.next;
}
}
head = head.next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment