C語言企業級單向鍊錶 只維護位址域

2021-09-11 01:49:05 字數 4744 閱讀 9646

//區別在於只維護位址域,記憶體釋放需要使用者自己來完成

#include

#include

typedef

struct linknode

linknodes;

typedef

struct linklist

linklists;

typedef

struct node nodes;

typedef

void

* llist;

//向使用者封裝資料

llist linklist_init()

;void

insert_linklist

(llist p_node, llist value_in)

;void

insert_pos_linklist

(llist p_node,

int pos, llist value_in)

;void

foreach_linklist

(llist p_node,

void

(*my_printf)

(void*)

);void

my_printf1

(void

* node_in)

;void

remove_pos_linklist

(llist p_node,

int pos)

;void

remove_value_linklist

(llist p_node,

void

* value,

int(

*my_compare)

(void*,

void*)

);intmy_compare1

(void

* value_in,

void

* node_in)

;void

length_linklist

(llist p_node)

;void

clear_linklist

(llist p_node)

;void

destory_linklist

(llist p_node)

;int

main()

; nodes n2 =

; nodes n3 =

; nodes n4 =

; nodes n5 =

; nodes n6 =

;printf

("---開始後插資料--\n");

insert_linklist

(link_head,

&n1)

;insert_linklist

(link_head,

&n2)

;insert_linklist

(link_head,

&n3)

;insert_linklist

(link_head,

&n4)

;insert_linklist

(link_head,

&n5)

;printf

("---後插資料完畢---\n");

foreach_linklist

(link_head, my_printf1)

;length_linklist

(link_head)

;printf

("---開始在特定位置插入資料--\n");

insert_pos_linklist

(link_head,1,

&n6)

;printf

("---在特定位置插入資料完畢---\n");

foreach_linklist

(link_head, my_printf1)

;length_linklist

(link_head)

;printf

("---開始在特定位置刪除資料--\n");

remove_pos_linklist

(link_head,0)

;printf

("---在特定位置刪除資料完畢---\n");

foreach_linklist

(link_head, my_printf1)

;length_linklist

(link_head)

;printf

("---開始在特定數值刪除資料---\n");

int id_temp =3;

remove_value_linklist

(link_head,

&id_temp, my_compare1)

;printf

("---在特定數值刪除資料完畢---\n");

foreach_linklist

(link_head, my_printf1)

;length_linklist

(link_head)

;printf

("---開始清空鍊錶---\n");

clear_linklist

(link_head)

;printf

("---清空鍊錶完畢---\n");

foreach_linklist

(link_head, my_printf1)

;length_linklist

(link_head)

;printf

("---開始銷毀鍊錶---\n");

destory_linklist

(link_head)

; link_head =

null

;printf

("---銷毀鍊錶完畢---\n");

foreach_linklist

(link_head, my_printf1)

;system

("pause");

return0;

}llist linklist_init()

void

insert_linklist

(llist p_node, llist value_in)

//linknodes *new_node = (linknodes*)malloc(sizeof(linknodes));

linknodes *my_node =

(linknodes *

)value_in;

//new_node -> next = my_node;

p_current -

> next = my_node;

node_head -

> length ++;}

void

insert_pos_linklist

(llist p_node,

int pos, llist value_in)

//linknodes *new_node = (linknodes*)malloc(sizeof(linknodes));

linknodes *my_node =

(linknodes *

)value_in;

//new_node -> next = my_node;

linknodes *p_current = node_head -

> p_head -

> next;

linknodes *p_privious = node_head -

> p_head;

int temp =0;

while

(p_current !=

null

)else

temp ++;}

node_head -

> length ++;}

void

foreach_linklist

(llist p_node,

void

(*my_printf)

(void*)

)}void

my_printf1

(void

* node_in)

void

remove_pos_linklist

(llist p_node,

int pos)

else}}

void

remove_value_linklist

(llist p_node,

void

* value,

int(

*my_compare)

(void*,

void*)

)else}}

intmy_compare1

(void

*value_in,

void

*node_in)

void

length_linklist

(void

*p_node)

void

clear_linklist

(void

*p_node)

node_head -

> p_head -

> next =

null

; node_head -

> length =0;

}void

destory_linklist

(void

*p_node)

企業級鍊錶設計思路

define crt secure no warnings include include include 節點結構體 struct linknode 鍊錶結構體 struct llist 取個別名 typedef void linklist 鍊錶的初始化 返回鍊錶結構體 linklist init...

C語言 單向鍊錶

1.c語言單向鍊錶 2.鍊錶的 增,刪,查,遍歷 author mr.long date 2015 12 1 15 24 26 include include 結構定義 struct node 函式定義 void printnode struct node head struct node addf...

C語言 單向鍊錶

1 單向鍊錶的定義 struct student next作為同型別指標,指向與它所在節點一樣的節點。1 建立鍊錶 int main 定義建立函式create,建立乙個有n個節點的單向鍊錶 struct student create int n ptail next null return head...