I am trying to create a typical function to sort an unordered list using the bubble sort method. The problem I am having is that the values are not being swapped. I guess it's a problem with pointers, but I can't seem to see why.
The test list I keep using is just 1 2 4 3. I put in some cout lines and it appears that the pointers are all pointing to the right address when they need to. But afterwards I will call a print function and the list still unsorted. Is it because I have multiple pointers on one address so I need to change them all? Is there anything anyone can see wrong with the code?Code:void UnorderedList::bubbleSort() { if(size() <= 1) throw ListTooShortException(); for(Node* track = getHead()->getNext(); track != NULL; track = track->getNext()) while(track->getElement() < track->getPrevious()->getElement()) swapNodes(track->getPrevious(), track); } void UnorderedList::swapNodes(Node*& first, Node*& second) { Node* temp = first; first = second; second = temp; }