/*Following function has two version of reverse *One using ptr_to function, the one we did in the class, *is commented out. The ohter without ptr_to is now the *active one. If you want to test the first version *uncomment the first part and comment out the second. *Please report any bugs promptly at asabbir@hotmail.com *subject: BUG */ void linked_list::reverse(){ ptrtype last=head; ptrtype prev; /* ptrtype next_to_last; ptrtype temp_head = ptr_to(size); for(int i=size;i>=2;--i){ last=ptr_to(i); next_to_last = ptr_to(i-1); last->next = next_to_last; next_to_last->next = NULL; } head = temp_head; */ if(head){ while(last->next != NULL) last = last->next; ptrtype temp_last=last; while(temp_last != head){ for(prev=head;prev->next!=temp_last;prev=prev->next); temp_last->next=prev; temp_last=prev; } head->next=NULL; head=last; } }