C語言實現單鏈表的基本操作

2021-09-19 09:58:25 字數 1926 閱讀 7156

typedef

struct nodelnode,

*linkedlist;

1>頭插法
linkedlist headinsert

(linkedlist *l)

return s;

}

2>尾插法
linkedlist tailinsert

(linkedlist *l)

return

(*l)

;}

void

add(linkedlist l,

int k,

int x)

s =(linkedlist)

malloc

(sizeof

(lnode));

s->data = x;

s->next = p->next;

p->next = s;

}

void

deletek

(linkedlist l,

int k)

q = p->next;

p->next = q->next;

free

(q);

}

void

update

(linkedlist l,

int k,

int x)

p->data = x;

}

int

getk

(linkedlist l,

int k)

return p->data;

}

#include

#include

#include

typedef

struct nodelnode,

*linkedlist;

//頭插法

linkedlist headinsert

(linkedlist *l)

return s;

}//尾插法

linkedlist tailinsert

(linkedlist *l)

return

(*l);}

//給第k給結點之後增加乙個值x

void

add(linkedlist l,

int k,

int x)

s =(linkedlist)

malloc

(sizeof

(lnode));

s->data = x;

s->next = p->next;

p->next = s;

}//刪除第k個結點

void

deletek

(linkedlist l,

int k)

q = p->next;

p->next = q->next;

free

(q);

}//更改第k個結點的值為x

void

update

(linkedlist l,

int k,

int x)

p->data = x;

}//查詢第k個結點的值

intgetk

(linkedlist l,

int k)

return p->data;

}//輸出鍊錶所有值

void

print

(linkedlist l)

printf

("\n");

}//主函式

intmain()

單鏈表的基本操作(C語言實現)

單鏈表的初始化,建立,插入,查詢,刪除。include include typedef int elemtype 定義結點型別 typedef struct node node,linkedlist 單鏈表的初始化 linkedlist linkedlistinit 單鏈表的建立1,頭插法建立單鏈表...

C語言實現單鏈表的基本操作

listnode.h ifndef listnode h define listnode h include stdio.h include assert.h include stdlib.h typedef int datatype typedef unsigned int size t type...

單鏈表 的基本操作 c語言實現

鍊錶的基本操作 c語言實現 執行環境 dev c 5.11 以下為原始碼,如有不正確的地方歡迎指正!include include define false 0 define true 1 typedef int datatype typedef struct nodelinklist linkli...