導航:首頁 > 源碼編譯 > 二叉查找演算法例題c語言

二叉查找演算法例題c語言

發布時間:2022-12-14 17:25:25

『壹』 C語言二叉樹遞歸演算法怎麼做

#include<stdio.h>
#include<string.h>

structtreenode{
intvalue;
treenode*left;
treenode*right;
};
typedeftreenode*BiTree;

voidvisit(treenode*node)
{
printf("%2d",node->value);
}

//結點總數
intnode(BiTreeT)
{
if(!T){
return0;
}
returnnode(T->left)+node(T->right)+1;
}

//前序
voidpreOrder(BiTreeT)
{
if(T){
visit(T);
preOrder(T->left);
preOrder(T->right);
}
}

//中序
voidinOrder(BiTreeT)
{
if(T){
inOrder(T->left);
visit(T);
inOrder(T->right);
}
}

//後序
voidpostOrder(BiTreeT)
{
if(T){
postOrder(T->left);
postOrder(T->right);
visit(T);
}
}

//葉子節點數
intleafnode(BiTreeT)
{
if(T){
if(!T->left&&!T->right)
return1;
else
leafnode(T->left)+leafnode(T->right);
}else{
return0;
}
}

intheight(BiTreeT)
{
if(T){
intlh=height(T->left);
intrh=height(T->right);
return(lh>rh?lh:rh)+1;
}else{
return0;
}
}

intmain()
{


return0;
}

『貳』 二叉樹c語言實現

#include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
char data;
struct node *lchild,*rchild;//
}BiTNode,*BiTree;
void CreatBiTree(BiTree &T)
{
char ch;
ch=getchar();
if (ch == ' ')
T = 0;
else {
T=(BiTNode*)malloc(sizeof(BiTNode));
T->data=ch;//生成根節點
CreatBiTree(T->lchild);//構造左子樹
CreatBiTree(T->rchild);//構造右子樹
}
}
void preorder(BiTree T)//前序遍歷
{
if (T!=NULL){
printf ("%c",T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
void inorder(BiTree T)//中序遍歷
{
if (T!=NULL){
inorder(T->lchild);
printf ("%c",T->data);
inorder(T->rchild);
}
}
void postorder(BiTree T)//後序遍歷
{
if (T!=NULL){
postorder(T->lchild);
postorder(T->rchild);
printf ("%c",T->data);
}
}
void main ()
{
cout<<"請輸入要創建的二叉樹包括空格:"<<endl ;
BiTree T;
CreatBiTree(T);//創建二叉樹
cout<<"前序遍歷的結果為:"<<endl;
preorder(T);
cout<<endl;
cout<<"中序遍歷的結果為:"<<endl;
inorder(T);
cout<<endl;
cout<<"後序遍歷的結果為:"<<endl;
postorder(T);
}

『叄』 數據結構c語言習題。編寫一個函數以二叉查找樹T和兩個有序的關鍵字 k1,

//創建二叉樹的原數組數據:40206010305070
//前序遍歷序列:40201030605070
//中序遍歷序列:10203040506070
//後序遍歷序列:10302050706040
//輸入關鍵字k1,k2的數值:3050
//列印的結果:
//403050
//
//二叉樹示意圖:
//
//40
///
//2060
////
//10305070

#include"stdio.h"
#include"stdlib.h"
structTree
{
intdata;
structTree*left;
structTree*right;
};
typedefstructTreeTreeNode;
typedefTreeNode*Bitree;

BitreeinsertNode(Bitreeroot,intdata)//插入結點
{
Bitreenewnode;
Bitreecurrent;
Bitreeback;
newnode=(Bitree)malloc(sizeof(TreeNode));
if(newnode==NULL)
{
printf(" 動態分配內存出錯. ");
exit(1);
}
newnode->data=data;
newnode->left=NULL;
newnode->right=NULL;
if(root==NULL)
{
returnnewnode;
}
else
{
current=root;
while(current!=NULL)
{
back=current;
if(current->data>data)
current=current->left;
else
current=current->right;
}
if(back->data>data)
back->left=newnode;
else
back->right=newnode;
}
returnroot;
}

BitreecreateTree(int*data,intlen)//創建二叉樹(非遞歸)
{
Bitreeroot=NULL;
inti;
for(i=0;i<len;i++)
{
root=insertNode(root,data[i]);
}
returnroot;
}


voidpreOrder(Bitreeptr)//先序遍歷(遞歸法)
{
if(ptr!=NULL)
{
printf("%d",ptr->data);
preOrder(ptr->left);
preOrder(ptr->right);
}
}

voidinOrder(Bitreeptr)//中序遍歷(遞歸法)
{
if(ptr!=NULL)
{
inOrder(ptr->left);
printf("%d",ptr->data);
inOrder(ptr->right);
}
}

voidpostOrder(Bitreeptr)//後序遍歷(遞歸法)
{
if(ptr!=NULL)
{
postOrder(ptr->left);
postOrder(ptr->right);
printf("%d",ptr->data);
}
}
//根據關鍵字k1和k2,進行區間查找(遞歸法)
voidbtreeSearch(Bitreeptr,intk1,intk2)
{
if(ptr!=NULL)
{
if(ptr->data<k1&&ptr->data<k2)
{
btreeSearch(ptr->right,k1,k2);
}
elseif(ptr->data==k1&&ptr->data<k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->right,k1,k2);
}
elseif(ptr->data>k1&&ptr->data<k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->left,k1,ptr->data);
btreeSearch(ptr->right,ptr->data,k2);
}
elseif(ptr->data>k1&&ptr->data==k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->left,k1,k2);
}
elseif(ptr->data>k1&&ptr->data>k2)
{
btreeSearch(ptr->left,k1,k2);
}
elseif(ptr->data==k1&&ptr->data==k2)
{
printf("%d",ptr->data);
}
else
{
printf("其它情況,當前節點的數值是%d",ptr->data);
}
}
}

intmain()
{
BitreeT=NULL;//T是二叉查找樹
intdata[]={40,20,60,10,30,50,70};
intlen;
inti;
intk1,k2;//關鍵字k1,k2
inttmp;

len=sizeof(data)/sizeof(int);
printf("創建二叉樹的原數組數據:");
for(i=0;i<len;i++)
{
printf("%d",data[i]);
}

T=createTree(data,len);//創建二叉樹

printf(" 前序遍歷序列:");
preOrder(T);
printf(" 中序遍歷序列:");
inOrder(T);
printf(" 後序遍歷序列:");
postOrder(T);

printf(" 輸入關鍵字k1,k2的數值:");
scanf("%d%d",&k1,&k2);
if(k1>k2)
{
tmp=k1;
k1=k2;
k2=tmp;
}
//根據關鍵字k1和k2,進行區間查找(遞歸法)
btreeSearch(T,k1,k2);

printf(" ");
return0;
}

『肆』 二叉查找樹遍歷問題

你好
很高興為你解答

答案是:下面是我的答案,已經在VC2010下測試通過 。

滿意請採納,謝謝
#include "stdafx.h" /*VC用的頭文件,在其它C中請刪除*/
#include <stdio.h> /*輸入六個整數45、24、53、12、37、9,插入數據元素13,刪除數據元素24和53 */
#include <stdlib.h>
typedef struct BiTNode/*結點結構 */
{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree Insert(BiTree T,int e)/*插入操作*/
{
BiTree p=T, f=NULL, s;
s=(BiTree)malloc(sizeof(BiTNode));
s->data=e;
s->lchild=s->rchild=NULL;
if (T==NULL) /*插入 s 為新的根結點*/
{
T = s;
}
else
{/*查找插入位置*/
while(p && p->data!=e) /*如果當前節點不為空且節點的值不是插入的值 */
{
if (p->data>e)
{f=p; p=p->lchild;} /*如果當前節點值大於插入的值,則記錄當前節點,並將節點的左節點作為當前節點 */
else
{f=p; p=p->rchild;} /*否則,節點的右節點作為當前節點 */
}
if (p==NULL&&e <f->data) /*如果當前節點為空並且插入的值小於父節點中的值; */
f->lchild = s; /*插入 s 為 f 的左孩子 */
else if(p==NULL&&e>f->data) f->rchild = s; /* 插入 s 為 f 的右孩子*/
else {printf("insert wrong!");exit(0);}
}
return T;
}

void Postorder(BiTree T)
{ /* 中序遍歷二叉樹 */
if (T)
{
Postorder(T->rchild); /* 遍歷左子樹 */
printf("%d ",T->data); /*訪問結點 */
Postorder(T->lchild);/* 遍歷右子樹 */
}
}

void main()
{
int e,i;
BiTree T;

T=NULL;
printf("input 6 num:\n");
for(i=1;i <7;i++)
{
scanf("%d",&e);
T=Insert(T,e);
}
printf("Postorder:\n");
Postorder(T);
printf("\n");

getchar();
}

『伍』 如何用C語言實現層次遍歷二叉樹

下面是c語言的前序遍歷二叉樹的演算法,在這里假設的節點元素值假設的為字元型,
說明:演算法中用到了結構體,也用到了遞歸的方法,你看看怎麼樣,祝你好運!
#include"stdio.h"
typedef
char
elemtype;
typedef
struct
node
//定義鏈表結構
{
elemtype
data;
//定義節點值
struct
note
*lchild;
//定義左子節點值
struct
note
*rchild;
//定義右節點值
}btree;
preorder(btree
*root)
//前序遍歷
{
if(roof!=null)
//如果不是空節點
{
printf("%c\n",root->data);
//輸出當前節點
preorder(root->lchild);
//遞歸前序遍歷左子節點
preorder(root->rchild);
//遞歸前序遍歷右子節點
}
return;
//結束
}

『陸』 幫忙看一下這個C語言程序二叉排序 高校分數線查詢

源程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define n 15
typedef int KeyType;
typedef char NameType;
typedef struct node{
KeyType key;
char name[n];
struct node *lchild,*rchild;
}BSTNode;

typedef BSTNode *BSTree;
BSTree CreateBST(void);
void SearchBST(BSTree T,KeyType Key);
void InsertBST(BSTree *Tptr,char *Name,KeyType Key);
void DelBSTNode(BSTree *Tptr,KeyType Key);
void InorderBST(BSTree T);
void BetweenSearchBST(BSTree T, KeyType Key1,KeyType Key2);
void LowSearchBST(BSTree T,KeyType Key);

main()
{
BSTree T;
char ch1,ch2;
KeyType Key;
KeyType Key1,Key2;
char *Name;
printf("建立高考各高校錄取最低分數線查詢表\n");
T=CreateBST();
ch1='y';
while (ch1=='y' || ch1=='Y')
{
printf("請選擇下列操作:\n");
printf("1------------------更新高考各高校錄取最低分數線查詢表\n");
printf("2------------------查詢等於給定分數線的高校\n");
printf("3------------------查詢小於給定分數線的高校\n");
printf("4------------------查詢在給定分數線段[Key1,Key2]中的所有高校.\n");
printf("5------------------插入一所高校的高考錄取最低分數線\n");
printf("6------------------刪除一所高校的高考錄取最低分數線\n");
printf("7------------------輸出高考各高校錄取最低分數線查詢表\n");
printf("8------------------ 退出\n");
scanf("\n%c",&ch2);
switch (ch2)
{
case '1': T=CreateBST();break;
case '2': printf("\n請輸入要查詢的分數:\n");
scanf("\n%d",&Key);
SearchBST(T,Key);
printf("\n查詢操作完畢。\n");break;
case '3': printf("\n請輸入要查詢的分數:\n");
scanf("\n%d",&Key);
LowSearchBST(T,Key);
printf("\n查詢操作完畢。\n");break;
case '4': printf("\n給定分數線段[Key1,Key2]:\n");
scanf("%d %d",&Key1,&Key2);
BetweenSearchBST(T,Key1,Key2);
printf("\n查詢操作完畢。\n"); break;
case '5': printf("\n請輸入要插入的高校名字:\n");
scanf("%s",Name);
printf("請輸入要插入的高校的最低分數線:\n");
scanf("\n%d",&Key);
InsertBST(&T,Name,Key);
printf("\n插入操作完畢。\n");break;
case '6': printf("\n請輸入要刪除的分數線:\n");
scanf("\n%d",&Key);
DelBSTNode(&T,Key);
printf("\n刪除操作完畢。\n");break;
case '7': InorderBST(T);
printf("\n分數線排序輸出完畢。\n");break;
case '8': ch1='n';break;
default: ch1='n';
}
}
}

BSTree CreateBST(void)
{
BSTree T;
KeyType Key;
char *Name;
T=NULL;
printf("請輸入一所高校的數據(輸入兩次0時結束輸入):\n");
scanf("%s",Name);
scanf("%d",&Key);
while (Key)
{
InsertBST(&T,Name,Key);
printf("請輸入下一所高校的數據(輸入兩次0時結束輸入):\n");
scanf("%s",Name);
scanf("%d",&Key);
}
return T;
}

void SearchBST(BSTree T, KeyType Key)
{
BSTNode *p=T;
while(p)
{
if(p->key==Key)
{
printf("已找到\n");
printf("%s",p->name);
printf("%5d",p->key);
return;
}
p=(Key<p->key) ? p->lchild:p->rchild;
}
printf("沒有找到\n");
}

void InsertBST(BSTree *T,char *Name,KeyType Key)
{
BSTNode *f,*p;int k;
p=(*T);
while(p)
{ k=strcmp(p->name,Name);
if(k==0)
{
printf("表中已有該高校不需插入\n");
return;
}
f=p;
p=(Key<p->key)?p->lchild:p->rchild;
}
p=(BSTNode*)malloc(sizeof(BSTNode));
strcpy(p->name,Name);
p->key=Key;
p->lchild=p->rchild=NULL;
if ((*T)==NULL) (*T)=p;
else if (Key<f->key) f->lchild=p;
else f->rchild=p;
}

void DelBSTNode(BSTree *T,KeyType Key)
{
BSTNode *parent=NULL, *p, *q,*child;
p=*T;
while(p)
{
if(p->key==Key) break;
parent=p;
p=(Key<p->key)?p->lchild:p->rchild;
}
if (!p) {printf("沒有找到要刪除的高校\n");return;}
q=p;
if (q->lchild && q->rchild)
for (parent=q,p=q->rchild; p->lchild; parent=p,p=p->lchild);
child=(p->lchild)?p->lchild:p->rchild;
if (!parent) *T=child;
else
{
if (p==parent->lchild)
parent->lchild=child;
else parent->rchild=child;
if (p!=q)
q->key=p->key;
}
free(p);
}

void InorderBST(BSTree T)
{
if(T!=NULL)
{
InorderBST(T->lchild);
printf("%s",T->name);
printf("%8d\n",T->key);
InorderBST(T->rchild);
}
}

void BetweenSearchBST(BSTree T, KeyType Key1,KeyType Key2)
{
BSTNode *p=T;
if(p)
{
if(p->key<Key2&&p->key>Key1)
{
printf("已找到\n");
printf("%s",p->name);
printf("%8d\n",p->key);
}
if(Key1>=p->key)p=p->lchild;
BetweenSearchBST(T->lchild,Key1,Key2);
if(Key2<=p->key)p=p->rchild;
BetweenSearchBST(T->rchild,Key1,Key2);
}
return;
}

void LowSearchBST(BSTree T, KeyType Key)
{
BSTNode *p=T;
if(p)
{
if(p->key<Key)
{
printf("已找到\n");
printf("%s",p->name);
printf("%8d\n",p->key);
}
LowSearchBST(p->lchild,Key);
LowSearchBST(p->rchild,Key);
}
else
return;
}

『柒』 c語言二叉樹問題求解~

#include"stdio.h"
intposition(int,int);
intmain(intargc,charconst*argv[])
{
intp,q,pos,times;
printf("請輸入數組的組數:");
scanf("%d",&times);
while(times>0)
{
printf("請輸入p,q:");
scanf("%d%d",&p,&q);
pos=position(p,q);
printf("%d ",pos);
times--;
}
return0;
}
intposition(intp,intq)
{
//printf("%d%d ",p,q);//這個可以看到過程
if(p==q)return1;
if(p>q)//右子樹
{
return2*position(p-q,q)+1;
}else//左子樹
{
return2*position(p,q-p);
}
}
//在主函數中調用position,可以得到相應地位置,簡單的驗證過,應該是正確的
//這個基本上涉及到了二叉查找樹,子節點和父節點索引的關系:2N,2N+1
//基本演算法就是這樣了,至於按你的要求輸入多組數據,可以自己做了

『捌』 急急,設計一個「二叉」查找演算法,將集合分成1/3和2/3大小的兩個集合

這個問題很簡單,排序,然後找到分割點,分。
就這樣。你說什麼二叉查找演算法,是不是說要對已經排序好的二叉樹進行分割?
題目也表達的比較亂。

『玖』 二叉查找樹演算法

#include <iostream>using namespace std;typedef struct _node{ int data; struct _node *pLeftPtr; struct _node *pRightPtr;}BTreeNode;class BinarySearchTree{public: BinarySearchTree(); ~BinarySearchTree(); bool Create(int* pIntArray,int arrLength); bool Insert(int data); // 查找節點,searchLength為搜索長度,返回值為true表示指定的數據存在,否則不存在 bool Find(int data, int* searchLength); // 中序輸出二叉樹 void MidOutput(); // 釋放內存 void Destroy(); void Delete(int data);protected: bool Insert(BTreeNode* pRoot, int data); bool Find(BTreeNode* pRoot,int data, int *searchLength); void Delete(BTreeNode* &pRoot, int data); void MidOutput(BTreeNode* pRoot); void Destroy(BTreeNode* pRoot);private: BTreeNode* m_pRoot; //二叉搜索樹根節點};BinarySearchTree::BinarySearchTree(){ m_pRoot = NULL;}BinarySearchTree::~BinarySearchTree(){ Destroy();}bool BinarySearchTree::Create(int* pIntArray,int arrLength){ for(int i=0; i<arrLength; i++) { if(!Insert(*(pIntArray+i))) return false; } return true;}bool BinarySearchTree::Insert(BTreeNode* pRoot, int data){ BTreeNode* pNewNode = new BTreeNode; if(pNewNode == NULL) return false; pNewNode->data = data; pNewNode->pLeftPtr = NULL; pNewNode->pRightPtr = NULL; BTreeNode* pCurrentNode = pRoot; BTreeNode* pParentNode = pCurrentNode;// 保存父節點的指針 int flag = 0;// 標記插入節點的位置 if(pCurrentNode == NULL) { m_pRoot = pNewNode; }else{ while(pCurrentNode) { if(data < pCurrentNode->data) { pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pLeftPtr; flag = 0; }else if(data > pCurrentNode->data){ pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pRightPtr; flag = 1; } } if(flag == 0) { pParentNode->pLeftPtr = pNewNode; }else{ pParentNode->pRightPtr = pNewNode; } } return true; }bool BinarySearchTree::Insert(int data){ return Insert(m_pRoot,data);}bool BinarySearchTree::Find(BTreeNode* pRoot,int data, int *searchLength){ if(pRoot == NULL) { *searchLength = 0; return false; } BTreeNode* pCurrentNode = pRoot; static int length = 0; while(pCurrentNode != NULL) { if(data == pCurrentNode->data) { *searchLength = length; cout<<"數字"<<data<<"存在二叉樹中,查找長度為: "<<endl<<length<<endl; return true; }else if(data < pCurrentNode->data) { length ++; pCurrentNode = pCurrentNode->pLeftPtr; }else{ length ++; pCurrentNode = pCurrentNode->pRightPtr; } } *searchLength = length; cout<<"數字"<<data<<"不在二叉樹中,查找長度為: "<<endl<<length<<endl; length = 0; // 每次查找結束,重新賦值為0 return false;}bool BinarySearchTree::Find(int data, int* searchLength){ return Find(m_pRoot,data,searchLength);}void BinarySearchTree::Destroy(BTreeNode* pRoot){ BTreeNode* pCurrentNode = pRoot; if(pCurrentNode == NULL) return; Destroy(pCurrentNode->pLeftPtr); Destroy(pCurrentNode->pRightPtr); delete pCurrentNode; m_pRoot = NULL;}void BinarySearchTree::Destroy(){ Destroy(m_pRoot);}void BinarySearchTree::MidOutput(BTreeNode* pRoot){ if(pRoot) { MidOutput(pRoot->pLeftPtr); cout<<pRoot->data <<" "; MidOutput(pRoot->pRightPtr); }}void BinarySearchTree::MidOutput(){ MidOutput(m_pRoot);}void BinarySearchTree::Delete(int data){ Delete(m_pRoot,data);}void BinarySearchTree::Delete(BTreeNode* &pRoot, int data){ if(!pRoot) return; else if(data == pRoot->data){ if(pRoot->pLeftPtr == NULL && pRoot->pRightPtr == NULL) // 葉子節點 { delete pRoot; pRoot = NULL; }else if(pRoot->pLeftPtr != NULL && pRoot->pRightPtr == NULL){ // 只有左子樹 BTreeNode* pNode = pRoot->pLeftPtr; delete pRoot; pRoot = pNode; }else if(pRoot->pLeftPtr == NULL && pRoot->pRightPtr != NULL){ // 只有右子樹 BTreeNode* pNode = pRoot->pRightPtr; delete pRoot; pRoot = pNode; }else{ // 有左右子樹 // 找到左子樹的最大節點 BTreeNode* pCurrentNode = pRoot->pLeftPtr; BTreeNode* pParentNode = NULL; while(pCurrentNode->pRightPtr != NULL) { pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pRightPtr; } pRoot->data = pCurrentNode->data; if(pParentNode) { pParentNode->pRightPtr = pCurrentNode->pLeftPtr; }else{ pRoot->pLeftPtr= pCurrentNode->pLeftPtr; } delete pCurrentNode; } }else if(data < pRoot->data) Delete(pRoot->pLeftPtr, data); else Delete(pRoot->pRightPtr, data);}void main(){ int data[8]; cout<<"請輸入整形數據, 數據用空格隔開, 回車鍵結束輸入"<<endl; for(int i=0; i<8; i++) cin>>data[i]; // int data[8] = {13,15,6,20,14,5,7,18}; BinarySearchTree tree; tree.Create(data,sizeof(data)/sizeof(data[0])); cout<<"插入數據後的二叉樹為: "<<endl; tree.MidOutput(); cout<<endl; int len_1=0; int len_2=0; tree.Find(14,&len_1); tree.Find(21,&len_2); tree.Delete(20); cout<<"刪除數字20後的二叉樹結果: "<<endl; tree.MidOutput(); cout<<endl; tree.Delete(15); cout<<"刪除數字15後的二叉樹結果: "<<endl; tree.MidOutput(); cout<<endl;}

『拾』 求用C語言實現二叉樹層次遍歷的遞歸演算法,謝謝!!!

演算法思想:層次遍歷目前最普遍用的就是隊列的那種方式,不是遞歸,但是用到while循環,既然題目要求用遞歸,可以用遞歸實現該while循環功能。演算法如下:
void TransLevele(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
if (r->left != NULL)
{
InsertQueue(r->left);
}
if (r->right != NULL)
{
InsertQueue(r->right);
}

Tree *t = DeleteQueue();
TransLevele(t);
}
//測試程序,創建樹輸入例如ABD##E##C##,根左右創建的方式。
如下代碼是測試通過的。
#include "stdlib.h"

#define MAX 100

typedef int Element;

typedef struct tree
{
Element ch;
struct tree *left;
struct tree *right;
}Tree;

typedef struct queue
{
Tree *a[MAX];
int front;
int rear;
}Queue;

Queue Qu;

void Init();
int InsertQueue(Element ch);
Tree *DeleteQueue();

void CreateTree(Tree **r);
void TransLevele(Tree *r);
void PrintTree(Tree *r);

int main()
{
Tree *r=NULL;
CreateTree(&r);
PrintTree(r);
printf("\n");
TransLevele(r);
return 0;
}

void Init()
{
int i=0;
for (i=0; i<MAX; i++)
{
Qu.a[i] = NULL;
}
Qu.front = 0;
Qu.rear = 0;
}
int InsertQueue(Tree *r)
{
if ( (Qu.rear+1)%MAX == Qu.front)
{
printf("Queue full!");
return 0;
}
Qu.a[Qu.rear] = r;
Qu.rear = (Qu.rear+1)%MAX;
return 1;
}
Tree *DeleteQueue()
{
if (Qu.front == Qu.rear)
{
printf("Queue empty");
return NULL;
}
Tree *t=NULL;
t = Qu.a[Qu.front];
Qu.front = (Qu.front+1)%MAX;
return t;
}

void CreateTree(Tree **r)
{
Element ch;
ch=getchar();
if (ch=='#')
{
(*r)=NULL;
return ;
}
*r = (Tree *)malloc(sizeof(Tree));
(*r)->ch = ch;
CreateTree(&((*r)->left));
CreateTree(&((*r)->right));
}
void PrintTree(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
PrintTree(r->left);
PrintTree(r->right);
}
void TransLevele(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
if (r->left != NULL)
{
InsertQueue(r->left);
}
if (r->right != NULL)
{
InsertQueue(r->right);
}

Tree *t = DeleteQueue();
TransLevele(t);
}

閱讀全文

與二叉查找演算法例題c語言相關的資料

熱點內容
網站源碼使用視頻 瀏覽:746
stc89c52單片機最小系統 瀏覽:452
郵件安全證書加密 瀏覽:416
雲伺服器如何訪問百度 瀏覽:279
常州電信伺服器dns地址 瀏覽:839
用小方塊製作解壓方塊 瀏覽:42
圖像壓縮編碼實現 瀏覽:68
特色功能高拋低吸線副圖指標源碼 瀏覽:71
西方哲學史pdf羅素 瀏覽:874
python最常用模塊 瀏覽:184
溫州直播系統源碼 瀏覽:112
程序員在上海買房 瀏覽:384
生活解壓游戲機 瀏覽:909
季羨林pdf 瀏覽:718
php支付寶介面下載 瀏覽:816
ipad怎麼把app資源庫關了 瀏覽:301
量柱比前一天多源碼 瀏覽:416
電子書app怎麼上傳 瀏覽:66
國家反詐中心app注冊怎麼開啟 瀏覽:804
全波差分傅里葉演算法窗長 瀏覽:41