Skip to content

Instantly share code, notes, and snippets.

@berkayk
Created January 29, 2016 10:04

Revisions

  1. berkayk created this gist Jan 29, 2016.
    30 changes: 30 additions & 0 deletions Problem2-4.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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;
    }
    }