雙向迴圈鍊錶和單向迴圈鍊錶一樣都是線性鏈式儲存結構,顧名思義雙向迴圈鍊錶就是在兩個方向都可以訪問任一資料。
呼叫下面**建立乙個結點作為頭結點,讓它的頭指標prev和尾指標next都指向自己,最後返回這個頭結點的堆位址。
}從鍵盤上獲得資料並返回,形式引數是乙個字串,用來說明獲得資料的用途。
int input_msg(char *msg)
在任意節點後插入乙個節點。
}將鍊錶中的所有資料列印出來。
void display_node(p_douoble_crclist head)
}
查詢鍊錶中是否有某個資料,有的話返回該資料所在節點的位址。
p_douoble_crclist find_data_to_list(p_douoble_crclist head, char *msg)
else
while(fdpos != head) //遍歷鍊錶
else
}return null;
}
刪除指定節點
p_douoble_crclist del_node_to_list(p_douoble_crclist head, p_douoble_crclist del_node)
while(dpos->next != del_node)
dpos->next = del_node->next;
del_node->next->prev = dpos;
del_node->next = del_node->prev = del_node;
return del_node;
}
修改某個節點的資料。
bool mod_node_data(p_douoble_crclist mod_node)
printf("change the data to:");
scanf("%d", &mod_data);
mod_node->data = mod_data;
return true;
}
將鍊錶中的節點空間逐個釋放。
合併兩個資料鏈表,注意需要優先斷開指向head2的指標。
}測試**
int test()
//初始化
p_douoble_crclist head1 = new_node(0);
p_douoble_crclist head2 = new_node(0);
//新增資料
for (size_t i = 0; i < 5; i++)
for (size_t i = 0; i < 5; i++)
// 顯示資料
printf("*******************************\n");
display_node(head1);
printf("*******************************\n");
display_node(head2);
printf("*******************************\n");
// 鏈結兩個表
cont_2_list(head1 , head2);
head2 = null ;
display_node(head1);
printf("*******************************\n");
return true;
}
雙向鍊錶和雙向迴圈鍊錶
和單向鍊錶相比,多了乙個前驅結點。如果他為空,那麼next和prior都指向自己。而對於雙迴圈鍊錶,只需要最後乙個元素的next指向head next,head next的prior指向最後乙個節點即可。新節點s插入鍊錶,s next給p結點,s prior給p prior,然後,p prior n...
迴圈鍊錶,雙向鍊錶
迴圈鍊錶 迴圈鍊錶與順序鍊錶之間的區別 迴圈鍊錶最後乙個資料的next指標域不為空,而是指向頭結點,其他基本操作大體相同,只是在判斷表結束的條件變為判斷節點的引用域是否為頭引用 雙向鍊錶 author neosong date oct 10,2017 4 43 01 pm program of in...
鍊錶 雙向迴圈鍊錶
雙向迴圈鍊錶與單鏈表一樣,都是邏輯連續 物理不連續的儲存方式,但它的效果要遠遠優於單鏈表,其結構如下 雙向迴圈鍊錶首先要有乙個頭節點,頭節點中不存放資料,真正的資料從頭節點的下乙個節點開始存放 然後每乙個節點都有兩個指標,分別指向前乙個節點和後乙個節點 最後頭尾相連,就成了雙向迴圈鍊錶。includ...