http://blog.csdn.net/passball/article/details/6126658
链表结构的反转,基本上把基本链表的内容都做了一遍。 比如,基本链表的创建,链表的遍历,然后就是反转链表了。 链表结构如下: a->b->c->d->e->NULL 弄三个指针head,mid,last,设置初值: head指向a mid指向NULL 然后开始指针运动了: while(head != NULL) { last=mid; mid=head; head=head->next; mid->next=last; } //last往mid走,mid往head走,head往head->next走,它们一直向前走,边走边mid->next=last,直到head==NULL为止。
第24题:反转链表 ListNode* ReverseIteratively(ListNode* pHead) //如果pNext指为空,则当前结点pNode设为头。 // reverse the linkage between nodes // move forward on the the list 或者,这样写: template<class T> |
|