Created
January 29, 2016 10:04
-
-
Save berkayk/c20694faeea42e986bc4 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
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