aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java/project2_strap012.java
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-11-27 16:44:00 -0600
committerRossTheRoss <msattr@gmail.com>2019-11-27 16:44:00 -0600
commita7def834fbd801f2e9359eff774dda91eea1490f (patch)
tree58949c03c67a8515efd5cf391996d18097d85141 /csci1913/Java/project2_strap012.java
parentWhat did I even do (diff)
downloadhomework-a7def834fbd801f2e9359eff774dda91eea1490f.tar
homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.gz
homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.bz2
homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.lz
homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.xz
homework-a7def834fbd801f2e9359eff774dda91eea1490f.tar.zst
homework-a7def834fbd801f2e9359eff774dda91eea1490f.zip
End me
Diffstat (limited to '')
-rw-r--r--csci1913/Java/project2_strap012.java45
1 files changed, 29 insertions, 16 deletions
diff --git a/csci1913/Java/project2_strap012.java b/csci1913/Java/project2_strap012.java
index 6c4ee34..3cbfa80 100644
--- a/csci1913/Java/project2_strap012.java
+++ b/csci1913/Java/project2_strap012.java
@@ -54,11 +54,12 @@ class Sort {
// NUMBER slots, without making new NODEs.
private static Node sortNodes(Node unsorted) {
- Node left = null, right = null, sorted = null;
+ Node left = null, right = null;
if (unsorted==null || unsorted.next==null) {
//unsorted is either empty or of length 1
return unsorted;
- } //Halving phase
+ }
+ //Halving phase
else {
int step = 1;
while (unsorted != null) {
@@ -79,34 +80,40 @@ class Sort {
//Sorting (recursive) Phase
left = sortNodes(left);
right = sortNodes(right);
- //Combining phase
- Node end = null;
+
+ //Combining phase, variables needed for Q funs
+ Node end = null, temp = null, sorted = null;
+ //Special Initial Case
if (left.number < right.number) {
- Node temp = left.next;
- sorted = left; end = left;
- left.next = null;
+ sorted = left;
+ end = left;
+ temp = left.next;
left = temp;
end.next = null;
} else {
- Node temp = right.next;
- end = right; sorted = right;
- right.next = null;
+ temp = right.next;
+ sorted = right;
+ end = right;
right = temp;
end.next = null;
}
+ //Loop for rearranging pointers. Easily the hardest part of the assignment
while (left != null && right != null) {
if (left.number < right.number) {
- Node temp = left.next;
+ end.next = left;
end = left;
- right = temp;
+ temp = left.next;
end.next = null;
- } else {
- Node temp = right.next;
+ left = temp;
+ } else { //Right is smaller or equal, put it at the end.
+ end.next = right;
end = right;
+ temp = right.next;
+ end.next = null;
right = temp;
- end.next = null;
}
- }
+ }
+
if (left == null) {
end.next=right;
} else if (right == null) {
@@ -131,5 +138,11 @@ class Sort {
writeNodes(sortNodes(makeNodes(3, 1, 4, 5, 9, 2, 6, 8, 7)));
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+ writeNodes(sortNodes(makeNodes(5,5,5,1,2,3,6,90,12,1,14)));
+ // [1, 1, 2, 3, 5, 5, 5, 6, 12, 14, 90]
+
+ writeNodes(sortNodes(makeNodes(1, 100, 6, 100, 1, 15, 10000, 12, 2, 0, -15)));
+ // [-15, 0, 1, 1, 2, 6, 12, 15, 100, 100, 10000]
}
} \ No newline at end of file