MCPcopy Create free account
hub / github.com/careercup/ctci / partition

Method partition

java/Chapter 2/Question2_4/QuestionC.java:7–28  ·  view source on GitHub ↗
(LinkedListNode node, int x)

Source from the content-addressed store, hash-verified

5public class QuestionC {
6
7 public static LinkedListNode partition(LinkedListNode node, int x) {
8 LinkedListNode head = node;
9 LinkedListNode tail = node;
10
11 /* Partition list */
12 while (node != null) {
13 LinkedListNode next = node.next;
14 if (node.data < x) {
15 /* Insert node at head. */
16 node.next = head;
17 head = node;
18 } else {
19 /* Insert node at tail. */
20 tail.next = node;
21 tail = node;
22 }
23 node = next;
24 }
25 tail.next = null;
26
27 return head;
28 }
29
30 public static void main(String[] args) {
31 int length = 20;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected