// REVERSE FUNCTION CODE-/**
* Reverses all links in the list. The former tail will now be the head
* and the former head will become the tail.
*
* \note The list should be reversed in one pass. No new nodes should be
* created.
*/
void SLL::reverse() {
if((head->next!=0) && (head !=0)){//if one node or no nodes do nothing
Node *temp, *pred, *temperary2;
for(temperary2=tail;temperary2!=head;temperary2=pred){//continue inner loop untill all next field's are changed except for head
for(pred=head, temp=head->next; temp != temperary2;//find predessor node and change current node to point to pred
pred= pred->next, temp=temp->next);
temperary2->next=pred;
}
temp = head;//switch head
head=tail;// and
tail=temp;//tail nodes
tail->next=0;//initilize tail's next field to NULL
}
}
**************************************************************************************************
TEST THAT DOESN'T work:
cout << endl << "Testing Reverse: " << endl;
SLL list2;
cout << "before call to Reverse: " << endl;
list2.printAll();
list2.reverse();
cout << "after call to Reverse: " << endl;
list2.printAll();