※数据结构※→☆线性表结构(list)☆============单向循环链表结构(list circular single)(四)
循环链表是另一种形式的链式存贮结构。它的特点是表中最后一个结点的指针域指向头结点,整个链表形成一个环。
单循环链表——在单链表中,将终端结点的指针域NULL改为指向表头结点或开始结点即可。
循环链表的特点是无须增加存储量,仅对表的链接方式稍作改变,即可使得表处理更加方便灵活。
注意:
①循环链表中没有NULL指针。涉及遍历操作时,其终止条件就不再是像非循环链表那样判别p或p->next是否为空,而是判别它们是否等于某一指定指针,如头指针或尾指针等。
②在单链表中,从一已知结点出发,只能访问到该结点及其后续结点,无法找到该结点之前的其它结点。而在单循环链表中,从任一结点出发都可访问到表中所有结点,这一优点使某些运算在单循环链表上易于实现。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以后的笔记潇汀会尽量详细讲解一些相关知识的,希望大家继续关注我的博客。
本节笔记到这里就结束了。
潇汀一有时间就会把自己的学习心得,觉得比较好的知识点写出来和大家一起分享。
编程开发的路很长很长,非常希望能和大家一起交流,共同学习,共同进步。
如果文章中有什么疏漏的地方,也请大家指正。也希望大家可以多留言来和我探讨编程相关的问题。
最后,谢谢你们一直的支持~~~
C++完整个代码示例(代码在VS2005下测试可运行)
AL_ListCircularSingle.h
#ifdef TEST_AL_LISTCIRCULARSINGLEAL_ListCircularSingle<DWORD> cListCircularSingle;BOOL bEmpty = cListCircularSingle.IsEmpty();std::cout<<bEmpty<<std::endl;int array[15]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};for(int i=0;i<15;i++)cListCircularSingle.Insert(cListCircularSingle.Length(), array[i]);bEmpty = cListCircularSingle.IsEmpty();std::cout<<bEmpty<<std::endl;//test the interfaceDWORD dwListSeqLen = cListCircularSingle.Length();std::cout<<dwListSeqLen<<std::endl;DWORD dwFind = cListCircularSingle.Find(16);std::cout<<dwFind<<std::endl;dwFind = cListCircularSingle.Find(12);std::cout<<dwFind<<std::endl;BOOL bElement = cListCircularSingle.IsElement(16);std::cout<<bElement<<std::endl;bElement = cListCircularSingle.IsElement(14);std::cout<<bElement<<std::endl;BOOL bInsert = cListCircularSingle.Insert(0, 0);std::cout<<bInsert<<std::endl;bInsert = cListCircularSingle.Insert(16, 16);std::cout<<bInsert<<std::endl;bInsert = cListCircularSingle.Insert(16, 999);std::cout<<bInsert<<std::endl;BOOL bRemove = cListCircularSingle.Remove(9846354);std::cout<<bRemove<<std::endl;bRemove = cListCircularSingle.Remove(999);std::cout<<bRemove<<std::endl;bRemove = cListCircularSingle.Remove(10);std::cout<<bRemove<<std::endl;INT it = 0x00;for (DWORD i=0; i<cListCircularSingle.Length(); i++) {it = cListCircularSingle.Get(i);std::cout<<it<<std::endl;}DWORD dwSet = cListCircularSingle.Set(16, 999);std::cout<<dwSet<<std::endl;dwSet = cListCircularSingle.Set(0, 888);std::cout<<dwSet<<std::endl;dwSet = cListCircularSingle.Set(11, 777);std::cout<<dwSet<<std::endl;for (DWORD i=0; i<cListCircularSingle.Length(); i++) {it = cListCircularSingle.Get(i);std::cout<<it<<std::endl;}cListCircularSingle.Clear();bEmpty = cListCircularSingle.IsEmpty();std::cout<<bEmpty<<std::endl;dwListSeqLen = cListCircularSingle.Length();std::cout<<dwListSeqLen<<std::endl;bInsert = cListCircularSingle.Insert(1, 999);std::cout<<bInsert<<std::endl;bInsert = cListCircularSingle.Insert(0, 666);std::cout<<bInsert<<std::endl;bRemove = cListCircularSingle.Remove(666);std::cout<<bRemove<<std::endl;bEmpty = cListCircularSingle.IsEmpty();std::cout<<bEmpty<<std::endl;dwListSeqLen = cListCircularSingle.Length();std::cout<<dwListSeqLen<<std::endl;#endif