首页 > 其他 > 详细

循环链表总结

时间:2015-04-19 11:18:24      阅读:126      评论:0      收藏:0      [点我收藏+]

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

  无论哪种链表,总之新建一个哨位节点对于链表的插入操作时方便的,它保证了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

 

循环链表总结

原文:http://www.cnblogs.com/zhangshixu/p/4438709.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!