單鏈表的基本操作

2021-08-09 09:44:36 字數 616 閱讀 1628

首先預定義鍊錶結構和結點

typedef

struct nodenode;

typedef

struct node *linklist; /*定義linklist*/

接下來貼幾個基本操作

/*初始條件:順序線性表l 不存在*/

/*操作結果:建立乙個頭結點*/

node *linklistinit()

p->next = null;

return p;

}/*初始條件:順序鍊錶l 已存在*/

/*操作結果:在鍊錶l 中填入元素*/

node *linklistcreat()

}/*初始條件:順序線性表l 已存在,1 <= i <= listlength(l)*/

/*操作結果:用e 返回l 中第i 個資料元素的值*/

status getelem(linklist l, int i, elemtype *e)

if(!p || j > i)

* e = p->data; /*取第i 個結點的資料*/

return ok;

}

單鏈表基本操作

include include include include includeusing namespace std typedef struct node node,plinklist plinklist createfromhead node pstnode node malloc sizeof...

單鏈表基本操作

單鏈表的初始化,建立,插入,查詢,刪除。author wang yong date 2010.8.19 include include typedef int elemtype 定義結點型別 typedef struct node node,linkedlist 單鏈表的初始化 linkedlist...

單鏈表基本操作

include using namespace std define namelenth 20 define ok 0 define error 1 typedef struct flagnode node 生成結點 inline node newnode 銷毀化煉表 void destroylin...