0)// 循环链表还有元素从头开始删{struct Value* pv = (struct Value*) CircleList_Delete(list,0);printf("%d\n",pv->v);}printf("\n");CircleLis。数据结构系列--循环链表( 四 )。" />

数据结构系列--循环链表( 四 )

< 2*CircleList_Length(list);i++){struct Value* pv = (struct Value*) CircleList_Get(list,i)printf("%d\n",pv->v);}printf("\n");while( CircleList_Length(list) > 0)// 循环链表还有元素从头开始删{struct Value* pv = (struct Value*) CircleList_Delete(list,0);printf("%d\n",pv->v);}printf("\n");CircleList_Insert(list,( CircleListNode*)&V1, CircleList_Length(list));CircleList_Insert(list,( CircleListNode*)&V2, CircleList_Length(list)); CircleList_Insert(list,( CircleListNode*)&V3, CircleList_Length(list)); CircleList_Insert(list,( CircleListNode*)&V4, CircleList_Length(list)); CircleList_Insert(list,( CircleListNode*)&V5, CircleList_Length(list));CircleList_Insert(list,( CircleListNode*)&V6, CircleList_Length(list)); CircleList_Insert(list,( CircleListNode*)&V7, CircleList_Length(list)); CircleList_Insert(list,( CircleListNode*)&V8, CircleList_Length(list)); for(i=0;i < CircleList_Length(list);i++)// 查看八个人是否在循环链表中{struct Value* pv = (struct Value*) CircleList_Next(list)// 先将当前的返回再移动printf("%d\n",pv->v);}printf("\n");CircleList_Resert(list); // 重置游标// 解决约瑟夫问题while( CircleList_Length(list) > 0)// 当链表中没有元素的时候停止出列{struct Value* pv = NULL;for(i = 1;i < 3;i++){CircleList_Next (list);// 这里的移动用游标来移动,所以很高效}pv = (struct Value*) CircleList_Current(list);printf("%d\n",pv->v);CircleList_DeleteNode(list,(CircleListNode*) pv );}CircleList_Destory(list); return 0;}
小结;
循环链表只是在单链表的基础上做了一个加强
循环链表完全可以代替单链表
【数据结构系列--循环链表】循环链表的Next和操作可以高效的遍历链表中的每个元素