注釋最全的C語言鍊錶的增刪改查

2021-08-14 19:19:19 字數 1389 閱讀 3366

//這是c語言的寫法,但會報錯,原因是len(當前的節點長度)

//無法在insert(插入)和deleted(刪除)之後改變

//不能使用delete是因為delete是c++中的乙個運算子

//最終我把改程式用c++寫了一遍,運用引用將len的真實值改變了

#include

#include

typedef

int elementtype;

typedef

struct node node, *pnode;//這裡node等價於struct node、、pnode等價於struct node*

pnode create_list(int len);

pnode change(pnode phead,int len);

void ergodic(pnode phead,int len);

pnode insert(pnode phead,int *len);

int main()

pnode create_list(int len)//這裡用pnode表示返回乙個結構體型別的指標

return phead;//返回乙個鍊錶的頭指標

}//++++++++++++++++++++++++++++++

void ergodic(pnode phead, int len)

}//++++++++++++++++++++++++++++++

pnode change(pnode phead, int len)

return phead;

}//+++++++++++++++++++++++++++++

//插入節點

pnode insert(pnode phead, int *len)

pnode e = (pnode)malloc(sizeof(node));

e->pnext = null;

printf("請輸入該節點的數值:");

int n;

scanf("%d", &n);

e->data = n;

e->pnext = p->pnext;

p->pnext = e;

len++;

return phead;

}//+++++++++++++++++++++++++++++++

//+++++++++++++++++++++++++++++

//刪除節點

pnode delete(pnode phead,int len)

q=p->pnext;

p->pnext=q->pnext;

free(q);

q=null;

return phead;

}

mysql增刪改查鍊錶 鍊錶的增刪改查

include include 先定義鍊錶裡面的元素。typedef struct nodemynode 定義整個鍊錶。typedef struct linkmylink int isempty to mylink mylink mylink 判斷鍊錶是否為空。int push to mylinki...

C語言 雙向鍊錶的增刪改查

主題 雙向鍊錶 功能 分別實煉表的插入 刪除 查詢操作 define crt secure no warnings include include typedef struct student stu,pstu 列印 void list print pstu phead,pstu ptail pri...

C語言 單向鍊錶的增刪改查

什麼是鍊錶?1.和陣列一樣,鍊錶也是一種線性表 2.從記憶體結構來看 鍊錶的記憶體結構是不連續的記憶體空間,是將一組零散的記憶體塊串聯起來,從而進行資料儲存的資料結構。3.鍊錶中的每乙個記憶體塊被稱為節點node。節點除了儲存資料之外,還要記錄鏈上 下乙個節點的位址,即後繼指標next。1.查詢單向...