雙向迴圈鍊錶的氣泡排序

2021-10-14 02:08:42 字數 1194 閱讀 1242

之前和群友水群的時候被認為雙向迴圈鍊錶不能實現氣泡排序,於是實現了一下,哪有什麼不能的 ,下面是純c的**實現.如果錯誤還請指正.

#include

#include

int n =0;

//鍊錶中的資料的數量++

struct two_way_list

;void

two_way_list_init

(struct two_way_list *head,

struct two_way_list* end)

void

two_way_list_insert

(struct two_way_list*

* head,

struct two_way_list*

* end,

int temp)

else

++ n;

return;}

void

two_way_list_print

(struct two_way_list *head,

struct two_way_list * end)

printf

("%d\n"

,temp->val)

;return;}

void

two_way_list_bubble

(struct two_way_list*

* h,

struct two_way_list*

* e)

if(temp -> behind == head)

if(temp == end)

temp = temp -> behind;}}

return;}

intmain()

two_way_list_bubble

(&head,

&end)

;two_way_list_print

(head,end)

;while

(scanf

("%d\n"

,&temp)

!=eof

)two_way_list_bubble

(&head,

&end)

;two_way_list_print

(head,end)

;return0;

}

雙向鍊錶和雙向迴圈鍊錶

和單向鍊錶相比,多了乙個前驅結點。如果他為空,那麼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...