@@ -0,0 +1,1378 @@
+import java.util.*;%0A%0Apublic class Problem2_4 %7B%0A  public static void main(String%5B%5D args) %7B%0A    Node list = makeList(new int%5B%5D%7B 1, 2, 3, 4, 5, 6, 7, 8, 1, 5, 7 %7D);%0A    printList(list);%0A    list = partition(list, 4);%0A    printList(list);%0A  %7D%0A%0A  public static Node partition(Node head, int threshold) %7B%0A    Node lt = null, gte = null, ltlast = null;%0A%0A    while (head != null) %7B%0A      Node next = head.next;%0A      if (head.val %3E= threshold) %7B%0A        head.next = gte;%0A        gte = head;%0A      %7D else %7B%0A        head.next = lt;%0A        lt = head;%0A        if (lt.next == null) %7B%0A          ltlast = lt;%0A        %7D%0A      %7D%0A      head = next;%0A    %7D%0A%0A    if (ltlast != null) %7B%0A      ltlast.next = gte;%0A      return lt;%0A    %7D else %7B%0A      return gte;%0A    %7D%0A  %7D%0A%0A  public static Node makeList(int%5B%5D arr) %7B%0A    // makes list backwards bc im a lazy pos%0A    Node head = null;%0A    for (int i : arr) %7B%0A      if (head == null) %7B%0A        head = new Node(i);%0A      %7D else %7B%0A        Node h = new Node(i);%0A        h.next = head;%0A        head = h;%0A      %7D%0A    %7D%0A    return head;%0A  %7D%0A%0A  public static void printList(Node head) %7B%0A    List%3CInteger%3E list = new ArrayList%3C%3E();%0A    while (head != null) %7B%0A      list.add(head.val);%0A      head = head.next;%0A    %7D%0A    System.out.println(list);%0A  %7D%0A%0A  static class Node %7B%0A    Node next;%0A    int val;%0A%0A    public Node(int val) %7B%0A      this.val = val;%0A    %7D%0A  %7D%0A%0A%7D%0A

Solve 2_4