diff options
Diffstat (limited to '')
-rw-r--r-- | csci1913/Java/project2_strap012.java | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/csci1913/Java/project2_strap012.java b/csci1913/Java/project2_strap012.java index ee09265..69793f0 100644 --- a/csci1913/Java/project2_strap012.java +++ b/csci1913/Java/project2_strap012.java @@ -54,32 +54,29 @@ class Sort { // NUMBER slots, without making new NODEs. private static Node sortNodes(Node unsorted) { - Node left = null, right = null, sorted = null; if (unsorted==null || unsorted.next==null) { - //unsorted list is either empty or of length 1 + //unsorted is either empty or of length 1 return unsorted; - } else { - //Halving phase - int step = 1; - while (unsorted != null) { - if (step % 2 == 0) { //Odd case - if (right == null) { - right = unsorted; - } else { - - } - } else { //Even case - if (left == null) { - left = unsorted; - } else { - - } + } //Halving phase + Node left = null, right = null, sorted = null; + int step = 1; + while (unsorted != null) { + if (step % 2 == 0) { //Odd case + if (right == null) { + right = unsorted; + } else { + right.next = unsorted; + } + } else { //Even case + if (left == null) { + left = unsorted; + } else { + left.next = unsorted; } - step++; - unsorted = unsorted.next; } + step++; + unsorted = unsorted.next; } - return sorted; } |