鍊錶的基礎操作建立插入刪除輸出

2021-10-03 18:16:05 字數 1558 閱讀 3085

#include

using

namespace std;

node *

creat

(int n)

;//建立有個n個結點的單鏈表

node *

insert

(node *h,

int m,

int l)

;//在單鏈表的第幾個元素之後插入值l

node *

remove

(node *h,

int t,

int n)

;//刪除鍊錶中值為t的元素

void

show

(node *h)

;//輸出n個結點的單鏈表

struct node

;int n,m,l,t;

//n為鍊錶結點的個數,m是在鍊錶第幾個之後插入元素l,t為要刪除的鍊錶中相同的元素

intmain()

node *

creat

(int n)

} p-

>next=h;

//構成鏈環

return h;

}

演示

//輸出n個結點的單鏈表

while

(p!=h)

;}

node *

insert

(node *h,

int m,

int l)

//在單鏈表的第幾個元素之後插入鍊錶

else p=p-

>next;

}while

(p!=h)

;return h;

}

node *

remove

(node *h,

int t,

int n)

//刪除鍊錶中值為t的元素

else

}while

(p!=h)

;}

鍊錶的簡單操作 建立,輸出,插入,刪除

include include define len sizeof struct student int n 0 節點數量 struct student head struct student creat void p2 next null return head void add int n 插入...

鍊錶的建立,插入,刪除,輸出基本操作

include include struct student 定義乙個學生結點,結點包括值域和指標域 typedef struct student list list createlist list insertnode list h,list s list deletenode list h,lo...

完整的鍊錶操作(定義 建立 插入 刪除 輸出)

include include struct student int icount 全域性變數表示鍊錶長度 struct student create else pnew struct student malloc sizeof struct student 再次分配結點記憶體空間 scanf s ...