循环链表总结

  重学数据结构,看到循环链表这块,有好多东西刚刚想起来,小总结下。

  无论哪种链表,总之新建一个哨位节点对于链表的插入操作时方便的,它保证了head节点。

  对于边界节点要特殊处理,删除的时候,如果是链尾节点,需要将其前驱节点next域置为NULL,如果是哨位节点后的第一个需要重新设置head节点next值

 1 template <class T>
 2 bool CircleLinkedList<T>::Delete(T & item,int index){
 3     Node<T> *curr = Find(index);
 4     if(curr == NULL) return false;
 5     item = curr->GetData();
 6     if(curr->GetPre() != head)
 7         curr->GetPre()->SetNext(curr->GetNext());
 8     else
 9         head->SetNext(curr->GetNext());
10     if(curr->GetNext() != NULL)
11         curr->GetNext()->SetPre(curr->GetPre());
12     else
13         curr->GetPre()->SetNext(NULL);
14     delete curr;
15     return true;
16 }
View Code

 

posted @ 2015-04-19 10:27  darkhorsezsx  阅读(176)  评论(0)    收藏  举报