Note that there are some explanatory texts on larger screens.

plurals
  1. POMy bubble sort over a double linked list cuts off the first node of the list for some reason
    primarykey
    data
    text
    <p>Here's the method</p> <pre><code>public void sortStudentsAlphabeticallyByFirstName() { StudentNode unsorted = tail; StudentNode current = header; while(unsorted.prevNode() != null) { while(current != unsorted) { int result = (current.getFirstName()).compareToIgnoreCase(current.nextNode().getFirstName()); if(result &gt; 0) //If in wrong order lexicographically { StudentNode temp = current; StudentNode next = current.nextNode(); StudentNode previous = current.prevNode(); StudentNode nextNext = next.nextNode(); if (numberOfStudents() == 2) { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(null); current.setPrev(null); unsorted = temp; } else if(nextNext == null) //If at penultimate student therefore last comparison { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(null); previous.setNext(current); current.setPrev(previous); unsorted = temp; } else if(previous == null) //if at beginning of student list { if(current.nextNode() == unsorted) { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(nextNext); nextNext.setPrev(temp); current.setPrev(null); unsorted = temp; //swap unsorted back to correct position } else { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(nextNext); nextNext.setPrev(temp); current.setPrev(null); } } else //else if in the middle of the list { if(current.nextNode() == unsorted) { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(nextNext); nextNext.setPrev(temp); previous.setNext(current); current.setPrev(previous); unsorted = temp; } else { current = current.nextNode(); current.setNext(temp); temp.setPrev(current); temp.setNext(nextNext); nextNext.setPrev(temp); previous.setNext(current); current.setPrev(previous); } } } current = current.nextNode(); } current = header; unsorted = unsorted.prevNode(); } } </code></pre> <p>Can anyone see why it cuts off the beginning of the list when I try to iterate the list again? I've used the debugger and it seems to run like it should, but I can't work out why it's doing it.</p> <p>Here's the iterate list method as well if it helps</p> <pre><code>public void itterateList() { StudentNode u = header; while(u != null) { System.out.println(u.getFirstName()+" "+u.getSurname()); u = u.nextNode(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload