筆記 鍊錶的操作

2021-08-31 18:16:00 字數 1300 閱讀 3456

typedef struct node

node;

typedef    struct node *linklist;

// 查詢第i個結點,將鍊錶l中的第i個結點的資料存入e

int list_get(linklist l, int i, int *e)

// while出來之後,p是第i個結點(1+i-1);若p指向表頭,迴圈i-1次,while出來後p是第i-1個結點(0+i-1)

if(!p || j>i)

*e = p->data;

return 1;

}

// 插入結點

// 在鍊錶l的第i個結點之前,插入結點s, s的資料域是e;

int list_insert(linklist *l, int i, int e)

if(!p || j>i)    //if(p == null || j>i)

// 插入結點s

s = (linklist)malloc(sizeof(node));

s->data = e;

s->next = p->next;

p->next = s;

return 1;

}

// 刪除結點

// 刪除鍊錶l的第i個結點,將該結點的資料儲存到e;

int list_insert(linklist *l, int i, int *e)

if(!p || j>i)

q = p->next;

p->next = q->next;

*e = q->data;

free(q);

return 1;

}

// 建立鍊錶 —— 頭插法,產生n個元素的帶頭結點的鍊錶l

void create_list_head(linklist *l, int n)

}

// 建立鍊錶 —— 尾插法,產生n個元素的帶頭結點的鍊錶l

void create_list_tail(linklist *l, int n)

r->next = null;

}

// 刪除鍊錶,l已經存在

int delete_list(linklist *l)

*l->next = null;    // 最後再將頭結點的指標域為空

return 1;

}

鍊錶的操作

鍊錶是資料結構中的乙個重要組成部分,對鍊錶操作的熟練度怎麼要求都不過分。只有部分核心 主要內容 1 鍊錶的建立 2 鍊錶的釋放 3 鍊錶的查詢 4 鍊錶中節點的插入 5 鍊錶中節點的刪除 6 鍊錶的反轉 7 兩個鍊錶的連線 define max 15 節點宣告 struct list typedef...

鍊錶的操作

結點0為頭結點,不儲存有意義的資料 從結點1開始儲存有意義的資料 include include includetypedef struct node node,pnode pnode create list 建立乙個新鍊錶 void show list pnode 遍歷顯示鍊錶 void add ...

鍊錶的操作

鍊錶是面試中常考的型別,因為只有幾行就可以了。下面是一些鍊錶 keshan.cpp 定義控制台應用程式的入口點。include stdafx.h include include define null 0 define len sizeof struct node struct node 列印鍊錶 ...