無頭單鏈表排序

2021-08-07 16:05:03 字數 1664 閱讀 7557

(1)無頭頭插單鏈表排序:

(思路:在原煉表中逐個比較大小,將最小的插入新的鍊錶(插入順序按照尾插的順序))

#include #include typedef struct person

per;

per *head_list(per *one, int num) //頭插

void show(per *head) //遍歷

while(head)

}void *sort(per *head) //排序

if(null == head->next) //若煉表中只有乙個數,則不用比較

per *min_pre = null;

per *min = head;

per *tmp = head;

per *new_list = null;

per *tail_sort = null;

while(head)

tmp = tmp->next;

}if(min == head)

else

if(null == new_list) //按照尾插將最小的數組成新的鍊錶

else

}return new_list;

}int main()

show(head);

printf("*****==after sort*****===\n");

head = sort(head);

show(head);

return 0;

}

(2)無頭尾插單鏈表排序:

(思路:在原煉表中逐個比較大小,將最小的插入新的鍊錶(插入順序按照頭插的順序))

#include #include typedef struct person

per;

per *tail_list(per *one, int num) //尾插

per *head = one;

while(one->next)

one->next = temp;

return head;

}void show(per *head)

while(head)

}per *sort(per *head)

if(null == head->next)

per *min = head;

per *tmp = head;

per *min_pre = null;

per *new_list = null;

per *tail_list = null;

while(head)

tmp = tmp->next;

}if(min == head)

else

min->next = new_list; //頭插順序插入新鍊錶

new_list = min;

}return new_list;

}int main()

show(head);

printf("*****====after sort**********==\n");

head = sort(head);

show(head);

return 0;

}

無頭單鏈表

鍊錶有單鏈表 雙鏈表和雙向迴圈鍊錶,每種鍊錶都有無頭和帶頭兩種,帶頭就是頭結點不存放資料元素 ifndef linklist h define linklist h include stdio.h include assert.h include string.h include malloc.h ...

單鏈表 無頭節點

就這書上 敲了一邊,加深印象,沒有頭結點的時候插入第乙個就有所不同了,而刪除時要找到前乙個,注意current link null 就這樣。include include include using namespace std struct linknode class list bool list...

無頭單鏈表的操作

節點結構 typedef定義 不帶頭節點的單鏈表 typedef int sdatatype 節點結構 typedef struct slistnode node,pnode 鍊錶結構 typedef定義 給乙個鍊錶結構 typedef struct slist slist 鍊錶的初始化 1.斷言 ...