1.單向迴圈鍊錶
區分單向鍊錶和單向迴圈鍊錶:單向迴圈鍊錶的尾指標指向頭結點。
2.單向迴圈鍊錶的基本操作
#include #include #define null 0
typedef struct node elemsn;
elemsn * creat_link(int ms); //建立乙個單向迴圈鍊錶
void print_link(elemsn *head); //輸出鍊錶
elemsn * delete_node(elemsn *head, int x); //刪除結點
elemsn * clear_link(elemsn *head); //刪除鍊錶
int main()
elemsn * creat_link(int ms) //帶表頭的單向鍊錶除了頭結點其餘結點
//建立方法一致,所以不用逆向建立
h = h->next; //確保h最後指向的是第乙個建立的結點,而非最後乙個
return h;
}void print_link(elemsn *head)
p = head;
do //使用do-while結構輸出
while(p != head);
printf("\n");
}elemsn * delete_node(elemsn *head, int x)
} do
p = p->next;
}while(p != head);
if(p->next == head) //刪除頭結點
單向迴圈鍊錶
單向迴圈鍊錶.cpp 定義控制台應用程式的入口點。include stdafx.h include include clinklist.h using namespace std int tmain int argc,tchar argv int n 5 測試空鍊錶 clinklistclist a...
迴圈單向鍊錶
typedef struct list list 初始化乙個迴圈單向鍊錶 void list init list head 判斷鍊錶是否為空 int is list empty list head 往迴圈單向鍊錶中插入乙個元素 prev 在prev元素後面插入 void list insert li...
單向鍊錶迴圈
include include include include includetypedef struct looplink looplink,plooplink 設定結點物件,包含兩個成員,nvalue和指向下乙個物件的指標pnext plooplink create phead nvalue 9...