資料結構 2 單鏈表插入和刪除節點

2021-07-16 21:56:08 字數 535 閱讀 2180

建立單鏈表,並輸出鍊錶,插入/刪除結點元素。

#includeusing namespace std;

struct node //node結構體,裡面有乙個node指標,用來指向下乙個node物件

;node* create(int n) //建立鍊錶,引數n表示結點的個數,返回型別是結點指標node*

p->next=null; //建立完成後,p->next指向null

return head;

}void display(node *head) //輸出鍊錶

coutwhile(--pos) //找到插入結點的位置

if((p=p->next)==null)

void remove(node *head,int pos) //鍊錶中刪除結點,引數pos表示刪除的位置

int main()

資料結構 單鏈表 建立,節點刪除,節點插入

unix環境2011 02 03 cpp view plain copy include include include typedef struct student node node creat 建立鍊錶 s num x memcpy s name,stu name,16 p next s p ...

資料結構 單鏈表建立 插入 刪除

include include include include include using namespace std typedef struct lnode linklist void initlist linklist head 初始化鍊錶 void createlista linklist ...

資料結構 刪除單鏈表偶數節點

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中偶數值的結點刪除。鍊錶結點定義如下 struct listnode 函式介面定義 struct listnode createlist struct listnode deleteeven struct listnode head 函式cr...