大話資料結構 鍊錶插入刪除操作

2021-09-13 15:35:48 字數 815 閱讀 1589

刪除l的第i個資料元素,並用e返回其值,l的長度減1.

迴圈結束後,p指向第i-1個結點,p->next指向第i個結點。

如果第i個結點不存在,則p->next==none,無法刪除第i個結點。

status listdelete

(linklist *l,

int i,elemtype *e)

if(p->next==none || j>i)

q=p->next;

*e=q->data;

p->next=q->next;

free

(q);

}

順序線性表l已經存在

操作結果:在l中第i個位置之前插入新的資料元素e,l的長度加1

首先要找到第i-1個結點,p指向第i-1個結點,s->next=p->next,p->next=s

迴圈結束後p指向第i-1個結點,如果p==none,則第i-1個結點為空,此時找不到第i個結點的位址,故無法在第i個結點之前插入元素

status listdelete

(linklist *l,

int i,elemtype *e)

if(p==none || j>i)

return error;

s=(linklist)

malloc

(sizeof

(node));

s->next=p->next;

p->next=s;

s->data=e;

return ok;

}

資料結構 鍊錶的插入刪除

遍歷列印鍊錶 public static void printlinkedlist listnode head system.out.println 1 頭插 public static listnode pushfront listnode head,int val public static l...

資料結構之鍊錶操作,建立,插入,刪除,查詢。

鍊錶操作 請戳這裡 這個博主寫的東西挺好,謝謝他 修改其中的一些地方。1.可以刪除節點。2.插入的時候按下標插入比較方便。3.typedef 使用需要注意。include include using namespace std struct node typedef struct node ptrn...

大話資料結構(一)鍊錶的基本操作

本人收藏的鍊錶的基本操作,已經經過上機測試,效果不錯!include include using namespace std typedef int datatype 鍊錶元素型別 typedef struct node 鍊錶結點 lnode,plnode 建立帶有頭結點的鍊錶 輸入ctrl z結束...