Skip to content

Commit

Permalink
cm
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojiedi committed Apr 17, 2022
1 parent feb7af0 commit 9763946
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions source/code/bitree_link_base.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@

// bitree_link_base.c
#include <stdio.h>
#include <stdlib.h>
#include "stack_link_base_for_tree.c"
#include "queue_link_base_for_tree.c"


// 判断树是否为空
int TreeIsEmpty(BsTree bt){
if( bt == NULL){
return 1 ;
}
return 0;
}

// 创建树
BsTree CreateBsTree(){
BsTree bt = (BsTree)malloc(sizeof(struct TreeNode));
return bt ;
}

// 前序递归
void PreOrderTraversalByRecursive(BsTree bt){
if (bt){
printf("%d ", bt->Data);
PreOrderTraversalByRecursive(bt->Left);
PreOrderTraversalByRecursive(bt->Right);
}
}

// 中续递归
void InOrderTraversalByRecursive(BsTree bt){
if (bt){
InOrderTraversalByRecursive(bt->Left);
printf("%d ", bt->Data);
InOrderTraversalByRecursive(bt->Right);
}
}

// 后续递归
void PosOrderTraversalByRecursive(BsTree bt){
if (bt){
PosOrderTraversalByRecursive(bt->Left);
Expand All @@ -39,6 +46,7 @@ void PosOrderTraversalByRecursive(BsTree bt){
}
}

// 前序迭代
void PreOrderTraversalByIterate(BsTree bt){
Stack s = CreateStack();
BsTree t = bt;
Expand All @@ -54,6 +62,8 @@ void PreOrderTraversalByIterate(BsTree bt){
}
}
}

// 中序迭代
void InOrderTraversalByIterate(BsTree bt){
Stack s = CreateStack();
BsTree t = bt;
Expand All @@ -70,6 +80,7 @@ void InOrderTraversalByIterate(BsTree bt){
}
}

// 后序迭代
void PostOrderTraversalByIterate(BsTree bt){
Stack s = CreateStack();
BsTree t = bt;
Expand All @@ -92,6 +103,9 @@ void PostOrderTraversalByIterate(BsTree bt){

}
}


// 层次遍历
void LevelOrderTraversal(BsTree bt){

Queue q = CreateQueue();
Expand All @@ -116,9 +130,9 @@ void LevelOrderTraversal(BsTree bt){
}
BsTree CreateDemoTree(){
/*
1
2 3
5 4 6
1
2 3
5 4 6
* */
Expand Down
1 change: 1 addition & 0 deletions source/code/bitree_link_base.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// bitree_link_base.h
#pragma once
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion source/code/bitree_list_base.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


int main(){

}


0 comments on commit 9763946

Please sign in to comment.