鍊錶初始化總結

2022-09-17 13:03:13 字數 1816 閱讀 4825

順序表:

宣告:struct seqlist

int last;

int data[12];

}seq,*seqlist;

初始化seqlist init_seqlist()

seqlist sl = malloc(sizeof(seq));

sl->last =-1;//標記位,用於判斷是表頭還是表尾

return sl;

插入操作(判斷是否滿,定位,移位(從後開始移),插入);

刪除操作(判斷是否為空,定位,移位,從定位的位置開始移);

單鏈表:

宣告:typedef struct node

lnt data;

struct node *next;

}listnode,*linklist;

初始化:

不帶表頭:

linklist init_list()

linklist l = null;

return l;

帶表頭(較常用)

linklist init_list()

插入操作(產生乙個新節點,定位,插入新節點)

刪除操作(判斷是否為空,定位,刪除節點)

反轉操作:

linklist p,q;

p=l->next;

l->next = null;//將鍊錶斷開

while(p!=null)

q = p->next;

p->next = l->next;

l->next = p;不斷在

l的後面迴圈插入p及

p的下個節點

p = q;

單向迴圈鍊錶:

宣告:typedef struct node

int data;

struct node *next;

}listnode,*linklist;

初始化:

不帶頭linklist init_list()

linklist l =null;

return l;

帶頭節點

linklist init_list()

不帶頭,插入操作(產生新節點,判斷是否為空,如果為空*l = new,new->next=new,

否則插入節點)注意因為有對

l操作,所以注意取位址。linklist l 是個變數而不是指標,只有

*l才是指標。

刪除操作(類似於單鏈表);

雙向迴圈鍊錶:

宣告:typedef struct node()

int data;

struct node *next,*prve;

}linknode,*linklist;

初始化:

linklist init_list()

linklist l = malloc(sizeof(listnode));

l->next = l;

l->prve = l;

return l

插入操作:(產生新節點,定位,插入)

尾部插入,中間插入只需將l

改成p;

new->n=l;

new->p = l->p;

l->p->n = new;

l->p=new; 

刪除操作:

p0->p->n = p0->n;

p0->n->p = p0->p;

p0->n = p0->p = null;

奇偶排序:將以上兩個結合。注意記錄q=p->prev;

方便節點向前移;

核心鍊錶:型別無關的雙向迴圈鍊錶。(核心鍊錶節點包含在宿主節點中):

鍊錶初始化

include include include struct node void init node plink int create node plink int insert node plink int print node plink int main void init node plin...

c語言鍊錶初始化

include include include typedef struct node node,pnode pnode init list else if len 0 對長度為負數的處理 pnode ptail phead ptail指向的是尾節點 ptail pnext null for i 0...

靜態鍊錶 初始化 插入

include include define ok 1 define true 1 define error 1 define false 1 define overflow 2 define elemtype int define status int 線性單鏈表 初始化 插入 取出 頭插法 合併...