aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-11-24 13:53:42 -0600
committerRossTheRoss <msattr@gmail.com>2019-11-24 13:53:42 -0600
commit19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e (patch)
treeb43e27026ed13705cf6540e87531246e252025a9 /csci1913/Java
parentThis project is no funno (diff)
downloadhomework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar.gz
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar.bz2
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar.lz
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar.xz
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.tar.zst
homework-19d945f9db2c94094d9ab0afb5ad8dd1c32bf39e.zip
Basically steal someone else's code lol
Diffstat (limited to 'csci1913/Java')
-rw-r--r--csci1913/Java/project2_strap012.java32
1 files changed, 17 insertions, 15 deletions
diff --git a/csci1913/Java/project2_strap012.java b/csci1913/Java/project2_strap012.java
index 69793f0..a102314 100644
--- a/csci1913/Java/project2_strap012.java
+++ b/csci1913/Java/project2_strap012.java
@@ -54,29 +54,31 @@ 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 is either empty or of length 1
return unsorted;
} //Halving phase
- Node left = null, right = null, sorted = null;
- int step = 1;
- while (unsorted != null) {
- if (step % 2 == 0) { //Odd case
- if (right == null) {
+ else {
+ int step = 1;
+ while (unsorted != null) {
+ Node next = unsorted.next;
+ if (step % 2 == 0) { //Even case
+ //Pops out first value and puts into Right
+ unsorted.next = right;
right = unsorted;
- } else {
- right.next = unsorted;
- }
- } else { //Even case
- if (left == null) {
- left = unsorted;
- } else {
- left.next = unsorted;
+ } else { //Odd case
+ // Pops out first value and puts into Left
+ unsorted.next = left;
+ left = unsorted;
}
+ step++;
+ unsorted = next;
}
- step++;
- unsorted = unsorted.next;
}
+ left = sortNodes(left);
+ right = sortNodes(right);
+
return sorted;
}