1 // #include <stdio.h> 2 // #include <stdlib.h> 3 4 // typedef char ElementType; 5 // typedef struct TNode *Position; 6 // typedef Position BinTree; ...
分类:
编程语言 时间:
2020-03-08 23:18:58
阅读次数:
153
本题要求用非递归的方法实现对给定二叉树的 3 种遍历。 函数接口定义: void InorderTraversal( BinTree BT ); void PreorderTraversal( BinTree BT ); void PostorderTraversal( BinTree BT ); ...
分类:
其他好文 时间:
2020-02-13 14:40:31
阅读次数:
95
6-6 二叉树的层次遍历 (6 分) 本题要求实现给定的二叉树的层次遍历。 函数接口定义: void Levelorder(BiTree T); T是二叉树树根指针,Levelorder函数输出给定二叉树的层次遍历序列,格式为一个空格跟着一个字符。 其中BinTree结构定义如下: typedef ...
分类:
其他好文 时间:
2019-11-25 20:29:17
阅读次数:
128
#include <stdio.h> #include <stdlib.h> #define MAX 1024 typedef struct bitnode { int data; struct bitnode *lchild; struct bitnode *rchild; }BinTree; B ...
分类:
其他好文 时间:
2019-11-22 00:32:33
阅读次数:
115
本题要求实现函数,判断给定二叉树是否二叉搜索树。 函数接口定义: 其中BinTree结构定义如下: 函数IsBST须判断给定的T是否二叉搜索树,即满足如下定义的二叉树: 定义:一个二叉搜索树是一棵二叉树,它可以为空。如果不为空,它将满足以下性质: 非空左子树的所有键值小于其根结点的键值。 非空右子树 ...
分类:
其他好文 时间:
2019-11-16 19:57:16
阅读次数:
120
一、前序排列 void PreorderTraversal(BinTree T)//前序遍历 { if( T ) { cout<<T->index <<" "<<T->data<<endl;//根 PreorderTraversal(T->pLChild);//左 PreorderTraversal ...
分类:
其他好文 时间:
2019-11-13 22:26:24
阅读次数:
90
前序非递归遍历(借用栈结构): ①将根节点入栈; ②判栈空,获取栈顶元素输出; ③判断右子树是否为空,再判断左子树是否为空,在回至②执行。 void PreOrder(BinTree bt) { stack<BinTree> astack; BinTreeNode * p; astack.push( ...
分类:
其他好文 时间:
2019-09-18 20:50:44
阅读次数:
127
void InorderTraversal( BinTree BT ) { if( BT ) { InorderTraversal( BT->Left ); /* 此处假设对BT结点的访问就是打印数据 */ printf("%d ", BT->Data); /* 假设数据为整型 */ Inorder ...
分类:
其他好文 时间:
2019-08-08 21:07:55
阅读次数:
96
int main(){ BinTree tree,parent,child; char ch[maxsize]; int i,n=0,k=0,j; printf("请给赋值二叉树:\n"); for(i=0;idata); printf("双亲结点为:%c",getParent(tree,paren... ...
分类:
其他好文 时间:
2019-06-06 19:03:22
阅读次数:
89
1 #include"stdio.h" 2 #define MaxSize 30 3 typedef char DataType; 4 typedef struct TreeNode{ 5 DataType data[MaxSize]; 6 int count; 7 }BinTree; 8 int ... ...
分类:
其他好文 时间:
2019-06-03 12:12:59
阅读次数:
103