c語言單迴圈鍊錶

2021-10-10 22:07:19 字數 3846 閱讀 3822

#ifndef __sclist_h__

#define __sclist_h__

#include

#include

#include

#define elemtype int

typedef

struct node

node,

*pnode;

typedef

struct list

list;

node *

_buynode

(elemtype x)

;void

initsclist

(list *list)

;void

push_back

(list *list,elemtype x)

;void

push_front

(list *list,elemtype x)

;void

show_list

(list *list)

;void

pop_back

(list *list)

;void

pop_fornt

(list *list)

;void

insert_val

(list *list,elemtype x)

;node*

find

(list *list,elemtype x)

;int

length

(list *list )

;void

delete_val

(list *list ,elemtype key)

;void

sort

(list *list)

;void

resver

(list *list)

;void

clear

(list *list)

;void

destroy

(list *list)

;#endif

#include

"sclist.h"

void

main()

show_list

(&mylist)

;break

;case2:

printf

("請輸入要插入的資料(-1結束):>");

while

(scanf

("%d"

,&item)

,item!=-1

)show_list

(&mylist)

;break

;case3:

show_list

(&mylist)

;break

;case4:

pop_back

(&mylist)

;break

;case5:

pop_fornt

(&mylist)

;break

;case6:

printf

("請輸入要插入的資料:>");

scanf

("%d"

,&item)

;insert_val

(&mylist,item)

;break

;case7:

printf

("請輸入要查詢的資料:>");

scanf

("%d"

,&item)

; p=

find

(&mylist,item);if

(p==

null

)else

break

;case8:

printf

("單鏈表的長度為:> %d\n"

,length

(&mylist));

break

;case9:

printf

("請輸入要刪除的值:> \n");

scanf

("%d"

,&item)

;delete_val

(&mylist,item)

;break

;case10:

sort

(&mylist)

;break

;case11:

resver

(&mylist)

;break

;case12:

clear

(&mylist)

;break

;case13:

destroy

(&mylist)

;break

;default

:printf

("輸入的命令有誤,請重新輸入.\n");

}}}

#include

"sclist.h"

node *

_buynode

(elemtype x)

void

initsclist

(list *list)

void

push_back

(list *list,elemtype x)

void

push_front

(list *list,elemtype x)

list->size++;}

void

show_list

(list *list)

printf

("nul.\n");

}void

pop_back

(list *list)

free

(list->last)

; list->last=p;

list->last->next=list->first;

list->size--;}

void

pop_fornt

(list *list)

list->size--;}

void

insert_val

(list *list,elemtype x)

if(p->next==list->last &&p->dataelse

}node*

find

(list *list,elemtype key)

if(p==list->first)

return p;

}int

length

(list *list )

void

delete_val

(list *list ,elemtype key)

if(p==list->last)

else

}void

sort

(list *list)

if(p->next==list->last &&p->next->datadata)

else}}

// 節點叫s

// 變數p

// 刪除 q

void

resver

(list *list)

}void

clear

(list *list)

list->last=list->first;

list->last->next=list->first;

list->size=0;

}void

destroy

(list *list)

單迴圈鍊錶 C語言

include include typedef int elemtype typedef int status typedef struct node listnode typedef listnode linklist 初始化單向迴圈鍊錶 void initlist linklist l 判斷單向...

約瑟夫環 C語言 單迴圈鍊錶

約瑟夫環 問題描述 編號為1,2,n的n個人圍坐一圈,每人持乙個密碼 正整數 一開始任選乙個正整數作為報數上限值m,從第乙個人開始自1開始順序報數,報到m時停止。報m的人出列,將他的密碼作為新的m值,從他的下乙個人開始重新從1報數,如此下去,直至所有人全部出列為止。試設計乙個程式求出列順序。問題分析...

單迴圈鍊錶

頭插 尾插 顯示 頭刪 尾刪 按值插入 按位置插入 查詢 長度 逆序 清除 摧毀 初始化 排序 按位置刪除 按值刪除 可以進一步優化 ifndef sclist h define sclist h include typedef int elementtype typedef enum bool 鍊...