C語言資料結構

2021-09-29 10:25:26 字數 2658 閱讀 3787

1、鍊錶的高階操作

void

reverse

(struct node *l)

p1->next = tailp;

l->next = p1;

}//鍊錶的反轉

2、鏈式儲存結構的棧(鏈棧)
struct snode

;//棧的節點定義

struct stack

;//棧的定義

struct stack *

initstack()

//棧的初始化

bool isstackempty

(struct stack *s)

//判斷是否棧空

void

push

(struct stack *s, elementtype e)

//入棧

void

pop(

struct stack *s, elementtype &e)

//出棧

3、鏈式儲存結構的佇列(鏈佇列)
struct qnode

;//佇列的節點定義

struct queue

;//佇列的定義

struct queue *

initqueue()

//佇列的初始化

bool isqueueempty

(struct queue *q)

//判斷佇列是否為空

void

enqueue

(struct queue *q, elementtype e)

//入隊

void

dequeue

(struct queue *q, elementtype &e)

//出隊

1、遍歷方式及其運用
void

preorder

(struct tnode *t)

}//先序遍歷遞迴實現

void

preorder

(struct tnode *t)if(

!isstackempty

(s))}}

//先序遍歷堆疊實現

void

inorder

(struct tnode *t)

}//中序遍歷遞迴實現

void

inorder

(struct tnode *t)if(

!isstackempty

(s))}}

//中序遍歷堆疊實現

void

postorder

(struct tnode *t)

}//後序遍歷遞迴實現

void

levelorder

(struct tnode *t)

}//層序遍歷佇列實現

void

preorder

(struct tnode *t)

}//更改先序遍歷實現輸出葉子節點

int

postorder

(struct tnode *t)

else

return0;

}//更改後序遍歷實現輸出樹高

2、二叉搜尋樹操作合集
struct tnode *

find

(struct tnode *bst, elementtype x)

return

null;}

//查詢二叉搜尋樹指定元素

struct tnode *

findmin

(struct tnode *bst)

//迭代查詢二叉搜尋樹的最小值

struct tnode *

findmax

(struct tnode *bst)

//迭代查詢二叉搜尋樹的最大值

struct tnode *

insert

(struct tnode *bst,elementtype x)

else

return bst;

}//遞迴插入二叉搜尋樹

struct tnode *

delete

(struct tnode *bst, elementtype x)

//左右子樹均存在,則在右子樹找到最小值替換,然後遞迴刪除右子樹的該元素

else

//左右子樹只存在一棵,則直接接上去

}return bst;

}//遞迴刪除二叉搜尋樹

3、平衡二叉樹調整方案

2、更新樹高,同時算出每個節點左右子樹的高度差

3、找到問題節點(左右子樹樹高差大於1的節點)

4、確定新插入的節點在問題節點的什麼位置(左左,左右,右左,右右)

5、根據位置進行平衡二叉樹的調整

資料結構 C語言 資料結構 查詢

二 查詢演算法的效能分析 三 基於線性表的查詢 四 基於樹的查詢 五 基於雜湊表的查詢 文章索引 分類typedef struct elemtype typedef struct sstable 從表中第一條 最後一條記錄開始,逐個進行記錄的關鍵字與給定值的比較,若某個記錄的關鍵字和給定值比較相等,...

C語言 資料結構

指標一維陣列 指標陣列 陣列指標 malloc函式 字元陣列 結構體聯合體 報錯問題 亂碼了,阿肆的github,這裡顯示正常,都是傳的md檔案。include include int main void ide根據檔案字尾選擇編譯器,cpp呼叫c 編譯器 c程式進行編譯是以源程式檔案為物件進行的,...

資料結構 c語言

目錄順序表樹圖 ifndef status h define status h include define true 1 define false 0 define ok 1 define error 0 ifndef overflow define overflow 2 endif ifndef...