資料結構 如何建立一棵樹,請給出c語言詳細**,謝謝
1樓:濮方雅
#include ""
#include ""
#define ok 1
#define error 0
#define overflow -2
typedef char telemtype;
typedef int status;
typedef struct bitnode bitnode, *bitree;
以下是建立二叉樹儲存結構,空節點輸入作為#結束標識return ok;
/ createbitree
void preorder(bitree t)} void inorder(bitree t)}void postorder(bitree t)}//以下是求葉子結點數。
void countleaf(bitree t,int& count)
/以下是求二叉樹的深度。
int depth(bitree t )
return depthval;
void main()
c語言高手進!高分採納寫的最好的!還有追加哦!關於資料結構二叉排序樹的編寫。
2樓:匿名使用者
關於程式演算法的優缺點沒什麼需要特別說明的,標準演算法加了乙個判斷,僅此而已,便於初學者的理解。
已經更改為你要的程式:
#include
#include
#define endin (-1) /*括號裡面的-1是結束標誌,可以在此改為其它的整數*/
typedef struct node node;
typedef node *bt;
bt bst(bt a,int d)
else if (ddata )
else if (d>=a->data )
return a;
bt init(void) /*建立一顆二叉排序樹,輸入結束標誌時結束輸入*/
return tree;
unsigned int inorder(bt a) /*中序遍歷輸出葉結點,並返回葉結點的個數*/
inorder(a->r);
return s;
void freetree(bt t) /*刪除樹*/
free(t);
int main(void)
3樓:網友
思路都有了,自己還寫不出來麼。
4樓:
二叉排序樹的特點是:對於任意的節點來說它本身的值都不小於它自己的左子樹,同時也不大於它的右子樹。
5樓:匿名使用者
匿名高手,你好。我是 108416879602,問題補充次數到了,因此只能通過這種方式通知你一下:如果寫得好再追加30分!
6樓:網友
我是 108416879602,我是指在程式旁邊要多幾條「註釋說明」,或最後註明一下你的程式有哪些優點(或特點),不是修改程式,寫得好再追加30分!!!
資料結構有關樹的度問題
7樓:
根節點沒有入度,計算總節點數目的時候還要算上根節點。
c++資料結構樹的應用
8樓:網友
#include
#include
using namespace std;
template
class tnode
tnode(const t& item, tnode*lptr = null, tnode*rptr = null)
nodevalue(item),left(lptr),right(rptr)
void createbtree(tnode*&r)}void fun1(tnode*&node)//先序遍歷}void fun2(tnode*&node)//中序遍歷}void fun3(tnode*&node)//後序遍歷}void f1(tnode*&node)else} }
void f2(tnode*&node)
elsewhile(p!=null||!
void f3(tnode*&node);doelse
else}while(!;
int main()
資料結構中關於用c++語言建立二叉樹的問題,求**,急!!!
9樓:網友
我有c語言版的,要不???
先建立乙個標頭檔案""(以下都要用到):
#include
#include
#include
typedef char datatype;
typedef struct node
bitnode, *bitree;
void createbitree(bitree *bt)}程式如下:
#include ""
void preorder(bitree root)/*先序遍歷二叉樹, root為指向二叉樹根結點的指標*/}void inorder(bitree root)}void postorder(bitree root)}void main()
#include ""
int leaf(bitree root)//求二叉樹中葉子結點的數目。
void main()
#include ""
int posttreedepth(bitree bt)else return(0);
void main()
資料結構 樹的問題
10樓:聽不清啊
右邊的表這樣解讀:
a的父結點為-1,即沒有父結點,它是根結點。
b、c、d的父結點都是0號結點,即結點a。
e、f的父結點都是1號結點,即b結點。
g的父結點是3號結點,即d結點。
h、i的父結點都是6號結點,即g結點。
11樓:it孤鶩
設定根為-1 a
根的孩子為0 b,c,d
第乙個孩子的孩子b為 1 ef第二個孩子的孩子 c為 2 沒有。
..這樣下去。。。就知道了吧。
c++語言寫的資料結構程式,幫忙改下,新手
12樓:
3個地方做了修改,加了註釋:
#include
#include
using namespace std;//增加使用名稱空間stdmain()
ofstream outfile("",ios::out);
if(!outfile){
cerr<<"cannot open "《這樣就不會馬上退出,可以看到結果了。
13樓:回頭的世界
你沒說是什麼問題啊?
14樓:網友
#include
using namespace std;//加上這一句#include
void main()
int n=50;
float f=;系統預設是double 將double轉化為float會發出警告。
outfile<<"n:" typedef struct qnode qnode,queueptr 定義兩個新資料型別qnode,queueptr,相當於 typedef struct qnode qnode typedef struct qnode queueptr 使用方法 qnode qdata struct qnode... 參考一下我的吧 include include include define list init size 100 define listincrement 10 define overflow 2 define ok 1 define error 0 define elemtype int typ... 你就直接學c 也應該要把c語言搞清楚,c語言的 寫起來要比c 繁瑣一些,不過學習的時候也理解更深刻。不用換,演算法 資料結構是程式設計的 核心,無論什麼語言 所用到的演算法 資料結構是內 一樣的容 唯一的影響可能是書裡一些c語言的 你可能不太懂 會對你的學習有一定的影響,不過影響不大 c 和c語言 ...資料結構C語言,資料結構和C語言有什麼區別?
C語言資料結構上機問題,求助謝謝
C語言資料結構演算法和C 資料結構演算法有什麼區別嗎??進來看看