#include
#include
/* ***************==
定義鍊錶資料結構
***************==
*/ struct node
;typedef struct node node;
typedef struct node * link;
/* ***************
功能:設頭結點
返回:void
***************
*/
void creat_link(link * head)
(*head) -> next = *head;
(*head) -> prior = *head;
}/*
********************=
功能:從頭部插入結點
返回:void
********************=
*/
void insert_node_head(link * head,link new_node)
}/*
********************=
功能:從尾部插入結點
返回:void
********************=
*/ void insert_node_tail(link * head,link new_node)
// }
tmp -> next = new_node;
new_node -> next = *head;
new_node -> prior = tmp;
(*head) -> prior = new_node;
/* 更好的寫法 */
//head->prior->next = newnode;
//newnode->prior = head->prior;
//newnode->next = head;
//head->prior = newnode;
}void insert_node_mid(link * head,link new_node,int num) //插入節點
else
if(tmp -> num == num) //判斷這個位置是否為真的節點
else}}
void delete_node(link * head,int num_delete)
else
if(tmp -> num == num_delete) //找到這個位置
else if(tmp -> next == (*head))
else
*/tmp->prior->next = tmp->next;
tmp->next->prior = tmp->prior;
free(tmp); //釋放
tmp = null; //置空
}else}}
void revers_link(link * head)
帶表頭結點的雙向迴圈鍊錶
include include 定義鍊錶資料結構 struct node typedef struct node node typedef struct node link 功能 設頭結點 返回 void void creat link link head head next head head p...
帶表頭節點的迴圈雙向鍊錶基本操作
include include struct node typedef struct node node typedef node link 函式功能 釋放鍊錶 void release link head p head head null free p 函式功能 建立節點 int node cre...
鍊錶 帶頭結點的雙向迴圈鍊錶
還需改進 creat node這個函式應有返回型別,來判斷新建結點是否成功,不然主函式中不管成不成功都會訪問該節點成員。改了這個函式,在主函式中create node後要判斷是否成功,不成功就提示並退出函式,退出前別忘了還要釋放鍊錶!同時create link這個函式中也要判斷head是否申請成功,...