InterviewSolution
Saved Bookmarks
| 1. |
How Do You Write A Function That Can Reverse A Linked-list? |
|
Answer» Answer : void reverselist(void) { if(HEAD==0) RETURN; if(head->next==0) return; if(head->next==tail) { head->next = 0; tail->next = head; } else { NODE* pre = head; node* CUR = head->next; node* curnext = cur->next; head->next = 0; cur-> next = head; for(; curnext !=0;) { cur->next = pre; pre = cur; cur = curnext; curnext = curnext->next; } curnext->next = cur; } } |
|