單鏈表 頭插法

2021-10-02 18:26:48 字數 1101 閱讀 9611

#include

#include 「list.h」

int main()

;node* head=null;

register int i=0;

int n=sizeof(a)/sizeof(a[0]);

for(;ireturn 0;

#include 「list.h」

#include

#include

node* list_creat(data dt)

p->data=dt;

p->next=null;

return p;}/*

函式:list_addhead

功能:插入乙個節點到鍊錶的頭部,使得該節點為頭節點

引數:dt:儲存到節點上的資料

head:插入的煉表頭指標

返回值:新的煉表頭指標

*/node* list_addhead(node* head, data dt)

p->data=dt;

p->next=head;

head=p;

return head;}/*

函式:list_showall

功能:遍歷整個鍊錶,並輸出節點資料

引數:鍊錶的頭指標

返回值:無

*/void list_showall(node* head)

printf("\n");}/*

函式:list_freeall

功能:**整個鍊錶

引數:鍊錶的頭指標

返回值:無

*/void list_freeall(node* head)

}#ifndef _list_h

#define _list_h

typedef int data;

node* list_creat(data dt);

node* list_addhead(node* head, data dt);

void list_showall(node* head);

void list_freeall(node* head);

typedef struct node

node;

#endif

單鏈表頭插法

include includetypedef struct node snode snode creat 建立頭結點 for i 1 idata x s next head head s return head int lenth snode l 求鍊錶的長度 return len snode ge...

單鏈表頭插法尾插法

標頭檔案如下 ifndef linklist h define linklist h define success 10000 define failure 10001 define size 10 typedef int element struct node typedef struct nod...

建立單鏈表(頭插法 尾插法)

1 頭插法建立單鏈表 生成的鍊錶中結點的順序與輸入的順序相反 頭插法建立單鏈表 status createlist l linklist l,int n return ok 2 尾插法建立單鏈表 與輸入的順序相同 尾插法建立單鏈表 status createlist tail linklist l,...