Author | Message |
---|---|
RandomAccess
Posts: 101
|
Posted 14:10 Mar 16, 2018 |
I created a while loop in the regroup method to search for while main nodes need to be swapped, with the following conditions: while(right != null){ It works fine for the most part, but for some reason there's a specific condition for when the first node is null, and the head's value is higher than the next node's, where it deletes the next node, which is weird because I'm using the same conditions for both, just without the first node which is null, as shown below: else if(first == null && last != null){//<-this condition deletes a node else{//<-this condition doesn't delete a node and does what it's supposed to, it's for when neither the first node or last node I'm checking are null Am I missing something? I figured two statements written the exact same way with the exact same variables would do the exact same thing. I don't know why it does this. and it troubles me. Last edited by RandomAccess at
14:12 Mar 16, 2018.
|
kknaur
Posts: 540
|
Posted 14:32 Mar 16, 2018 |
Maybe a different method for regrouping is in order. Instead of swapping nodes, why not iterate through your list and place the nodes one by one into a new configuration. You may need to hand trace your code to see what is going on, and failing that, you may need to rewrite the method piece by piece and check to see that each part is working before moving on to the next part. |