aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2019-11-24 11:50:01 -0600
committerRossTheRoss <mstrapp@protonmail.com>2019-11-24 11:50:01 -0600
commit344792b4d5f9c9a41f68d6efcc57c443574acdf2 (patch)
tree1a91c4c3332e35a2fcc3380a3e299ed4a064d05b /csci1913/Java
parentPush Project (diff)
downloadhomework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar.gz
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar.bz2
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar.lz
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar.xz
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.tar.zst
homework-344792b4d5f9c9a41f68d6efcc57c443574acdf2.zip
Redo project
Diffstat (limited to 'csci1913/Java')
-rw-r--r--csci1913/Java/project2_strap012.java68
1 files changed, 16 insertions, 52 deletions
diff --git a/csci1913/Java/project2_strap012.java b/csci1913/Java/project2_strap012.java
index 4010657..bc50856 100644
--- a/csci1913/Java/project2_strap012.java
+++ b/csci1913/Java/project2_strap012.java
@@ -54,69 +54,33 @@ class Sort {
// NUMBER slots, without making new NODEs.
private static Node sortNodes(Node unsorted) {
- Node left=null, right=null, sorted=null;
- boolean firstSort=true;
+ Node left = null, right = null, sorted = null;
if (unsorted==null || unsorted.next==null) {
//unsorted list is either empty or of length 1
return unsorted;
} else {
- //--HALVING PHASE--
- int oddeven = 0;
- boolean firstNodeR = true, firstNodeL = true;
- while (unsorted!=null) {
-
- if (oddeven%2==0) {
- if (firstNodeL) {
- left=unsorted;
- firstNodeL=false;
+ //Halving phase
+ int step = 1;
+ while (unsorted != null) {
+ // Node tL = left, tR = right;
+ if (step % 2 == 0) { //Odd case
+ if (right == null) {
+ right = unsorted;
} else {
- unsorted=left.next;
+ right.next=unsorted;
}
- } else {
- if (firstNodeR) {
- right=unsorted;
- firstNodeR=false;
+ } else { //Even case
+ if (right == null) {
+ left = unsorted;
} else {
- unsorted = right.next;
+ left.next=unsorted;
}
}
- oddeven++;
- unsorted=unsorted.next;
- }
- }
- //--SORTING PHASE--
- sortNodes(left); sortNodes(right);
- //--COMBINING PHASE
- while (left != null || right != null) {
- if (left.number>right.number) {
- if(firstSort) {
- sorted = left;
- firstSort = false;
- } else {
- sorted.next = left;
- }
- left = left.next;
- } else {
- if (firstSort) {
- sorted = right;
- firstSort = false;
- } else {
- sorted.next = right;
- }
- right = right.next;
- }
- }
- if (left==null) {
- while (right!=null) {
- sorted.next=right;
- right=right.next;
- }
- } else if (right==null) {
- while (left!=null) {
- sorted.next=left;
- left=left.next;
+ unsorted = unsorted.next;
+ step++;
}
}
+
return sorted;
}