相對於單鏈表多了乙個指標prev指向全面的節點
#include
#include
typedef
struct student linklist;
linklist *
create
(int n)
return head;
}/*正向列印節點的值*/
intprintlist
(linklist *list)
return coun;
}/*逆向列印節點的值*/
intprintlist1
(linklist *list)
return coun;
}/*改變某個節點的函式與單鏈表一致*/
void
change
(linklist *list,
int n)
if(t!=list)
else
}void
delete
(linklist *list,
int n)
if(t!=
null
)else
}void
insert
(linklist *list,
int n)
in =
(linklist *
)malloc
(sizeof
(linklist));
printf
("input insert data:");
scanf
("%d"
,&in->socre);if
(t!=
null
)else
}int
main()
結果顯示:
input the node num:
4the 1 data input:
1the 2 data input:
2the 3 data input:
3the 4 data input:
4double list socre:
1double list socre:
2double list socre:
3double list socre:
4double list reserve socre:
4double list reserve socre:
3double list reserve socre:
2double list reserve socre:
1the node num:
4insert node:
4input insert data:
5double list socre:
1double list socre:
2double list socre:
3double list socre:
4double list socre:
5double list reserve socre:
5double list reserve socre:
4double list reserve socre:
3double list reserve socre:
2double list reserve socre:
1the node num:
5change node:
3enter modify num:
8double list socre:
1double list socre:
2double list socre:
8double list socre:
4double list socre:
5double list reserve socre:
5double list reserve socre:
4double list reserve socre:
8double list reserve socre:
2double list reserve socre:
1the node num:
5delete node:
2double list socre:
1double list socre:
8double list socre:
4double list socre:
5double list reserve socre:
5double list reserve socre:
4double list reserve socre:
8double list reserve socre:
1the node num:
4
例子2,不可控制輸入引數
#include
#include
typedef
struct student linklist;
linklist *
create
(int n)
return head;
}int
change
(linklist *list,
int n)
} node->socre =
999;
return0;
}int
insert
(linklist *list,
int n)
} new =
(linklist *
)malloc
(sizeof
(linklist));
new->socre =
888;
new->next = node->next;
node->next->prev = new;
node->next = new;
new->prev = node;
return0;
}linklist *
delete
(linklist *list,
int n)
} new = node->next;
node->prev->next = node->next;
node->next->prev = node->prev;
free
(node);if
(n ==0)
return new;
else
return list;
}void
scan
(linklist *list)
while
(node != list)
;#else
dowhile
(node != list)
;#endif
}void
main()
結果
kayshi@ubuntu:
~/code/linked_list$ gcc double_linked_list.c &&
./a.out
socre is 100
socre is 96
socre is 97
socre is 98
socre is 99
====change==
====
==socre is 100
socre is 999
socre is 97
socre is 98
socre is 99
====insert==
====
==socre is 100
socre is 999
socre is 97
socre is 888
socre is 98
socre is 99
====delete==
====
==socre is 100
socre is 999
socre is 97
socre is 888
socre is 98
迴圈鏈表示例 求解約瑟夫問題
錯誤 debug assertion failed!迴圈鍊錶模板class include using namespace std template struct circlelinknode circlelinknode t d,circlelinknode next null data d li...
共享鏈表示例
共享鍊錶的應用小例項 前言 1 鍊錶 linked list 是一種常見的基礎資料結構,是一種線性表,但是並不會按線性的順序儲存資料,而是在每 個節點裡存到下乙個節點的指標 pointer 由於不必按順序儲存,鍊錶在插入的時候可以達到o 的複雜度,比另一種線性表 順序表快得多,但是查詢乙個節點或者訪...
C 雙向迴圈資料鏈表實現
最近在做乙個大專案。哈哈。就是開發乙個讓使用者自由搭建場景的軟體。最近一周都在解決畫面的問題。今天已經都給解決了。我們在實現畫面的過程中,需要獲取到閉合區間所有頂點以及沿著某一方向的順序儲存。這時候,選擇雙向迴圈鏈式資料表儲存資料再好不過了。下面就是鏈式資料表的 首先我們建立每乙個節點 環形雙向鍊錶...