《資料結構》 「鍊錶的建立等相關操作」

2021-10-12 01:16:44 字數 1035 閱讀 5310

//建立鍊錶並遍歷 ↓

#include

using namespace std;

//定義單鏈表型別

typedef

int elemtype;

typedef

struct lnodelnode,

* linklist;

//建立乙個鍊錶

void

createlist_l

(linklist &l,

int n)

}//遍歷鍊錶

void

printlist

(linklist l)

}//主函式

intmain

(void

)

//刪除乙個元素 ↓

//演算法2.9

intlistdelet_l

(linklist &l,

int i,elemtype &e)

//尋找要刪除的第i個節點,並令p指向其前驅if(

!(p->next)

||j>i-1)

return3;

q=p->next;

p->next=q->next;

//刪除操作

e=q->data;

free

(q);

return4;

}

//插入乙個元素 ↓

//插入乙個數(演算法2.8)

intlinkinsert_l

(linklist &l,

int i ,elemtype e)if(

!p||j>i-1)

return0;

s=(linklist)

malloc

(sizeof

(lnode));

s->data=e;

s->next=p->next;

p->next=s;

return1;

}

資料結構 迴圈鍊錶的相關操作

include include 結點的資料結構 typedef struct nodenode,pnode 迴圈鍊錶的資料結構 typedef struct linklistlinklist,clinklist 初始化迴圈鍊錶 bool initlist clinklist l l head nex...

資料結構(二)鍊錶的相關操作

以下是我在學習鍊錶及其相關介面操作時寫的 1.函式定義的 c 檔案 include linkedlist.h include include include 1.初始化 銷毀 void llistinit llist llist 2.頭插 void llistpushfront llist llis...

資料結構 鍊錶操作

include include include include typedef int datatype typedef struct slistnode slistnode slistnode creatnewnode datatype data 申請空間存放新鍊錶 void slistnodep...