
数据结构-anyView
cwx01perfect
这个作者很懒,什么都没留下…
展开
-
9.31
9.31④ 试写一个判别给定二叉树是否为二叉排序树的算法,设此二叉树以二叉链表作存储结构。且树中结点的关键字均不同。实现下列函数:Status IsBSTree(BiTree t);/* 判别给定二叉树t是否为二叉排序树。*//* 若是,则返回TRUE,否则FALSE */二叉树的类型BiTree定义如下:typedef struct {原创 2012-04-08 09:54:12 · 1457 阅读 · 0 评论 -
anyView 6.44
6.44编写递归算法:求二叉树中以元素值为x的结点为根的子树的深度,要求实现下列函数int Depthx(BiTree T, TElemType x);/*求二叉树中以值为x的结点为根的子树深度*/typedef struct BiTNode { TElemType data; BiTNode *lchild, *rchild;} BiTNode,原创 2012-05-20 18:11:36 · 1135 阅读 · 0 评论 -
anyView 6.65
6.65④ 已知一棵二叉树的前序序列和中序序列分别存于两个一维数组中,试编写算法建立该二叉树的二叉链表。要求实现以下函数:void BuildBiTree(BiTree &bt, int ps, char *pre, int is, char *ino, int n);/* 当前要建立的子树bt的元素总数为n,原创 2012-05-06 13:03:22 · 829 阅读 · 0 评论 -
09—EX25
实现下列函数:int Search(SSTable s, KeyType k);/* Index the element which key is k *//* in StaticSearchTable s. *//* Return 0 if x is not found. */静态查找表的类型SSTable定义如下:typedef stru原创 2012-04-08 09:52:25 · 520 阅读 · 0 评论 -
anyView 6.37
6.37③ 试直接利用栈的基本操作写出先序遍历的非递归形式的算法(提示:不必按3.3.2节介绍的从递归到非递归的方法而直接写出非递归算法)。要求实现下列函数:void PreOrder(BiTree bt, void (*visit)(TElemType)); /* 使用栈,非递归先序遍历二叉树bt, *//* 对每个结点的元素域data调用函数visit */原创 2012-04-08 09:51:25 · 449 阅读 · 0 评论 -
6.36③
6.36③ 若已知两棵二叉树B1和B2皆为空,或者皆不空且B1的左、右子树和B2的左、右子树分别相似,则称二叉树B1和B2相似。试编写算法,判别给定两棵二叉树是否相似。要求实现下列函数:Status Similar(BiTree t1, BiTree t2);/* 判断两棵二叉树是否相似的递归算法 */二叉链表类型定义:typedef struct BiT原创 2012-04-08 09:50:23 · 648 阅读 · 0 评论 -
anyView6.34
6.34③ 假定用两个一维数组L[1..n]和R[1..n]作为有n个结点的二叉树的存储结构, L[i]和R[i]分别指示结点i的左孩子和右孩子,0表示空。试写一个算法,先由L和R建立一维数组T[1..n],使T中第i(i=1,2,...,n)个分量指示结点i的双亲,然后判别结点u是否为结点v的子孙。要求实现以下函数:Status Dencend(Array1D原创 2012-04-08 09:49:29 · 587 阅读 · 0 评论 -
anyView6.33③
6.33③ 假定用两个一维数组L[1..n]和R[1..n]作为有n个结点的二叉树的存储结构, L[i]和R[i]分别指示结点i的左孩子和右孩子,0表示空。试写一个算法判别结点u是否为结点v的子孙。要求实现以下函数:Status Dencendant(Array1D L,Array1D R,int n,int u,int v);/* If node 'u' is th原创 2012-04-08 09:47:34 · 758 阅读 · 0 评论 -
1.16
◆1.16② 试写一算法,如果三个整数X,Y和Z的值不是依次非递增的,则通过交换,令其为非递增。要求实现下列函数:void Descend(int &x, int &y, int &z); /* 按从大到小顺序返回x,y和z的值 */*************************************************************vo原创 2012-04-08 12:30:05 · 502 阅读 · 0 评论 -
9.26
9.26② 试将折半查找算法改写成递归算法。 实现下列函数:int BinSearch(SSTable s, int low, int high, KeyType k);/* Index the element which key is k *//* in StaticSearchTable s. *//* Return 0 if x is not原创 2012-04-08 09:53:18 · 723 阅读 · 0 评论 -
6.43
6.43③ 编写递归算法,将二叉树中所有结点的左、右子树相互交换。要求实现下列函数:void Exchange(BiTree &bt);/* Exchange the left and right leaves of *//* bitree whose root node is bt */二叉链表类型定义:typedef struct BiT原创 2012-04-08 11:05:27 · 580 阅读 · 0 评论 -
6.42
6.42③ 编写递归算法,计算二叉树中叶子结点的数目。要求实现下列函数:void Leaves(BiTree bt, int &x);/* Count the leaf node of the BiTree *//* whose root node is bt to x. */二叉链表类型定义:typedef struct BiTNode {原创 2012-04-08 10:42:29 · 7248 阅读 · 0 评论 -
6.41
6.41③ 编写递归算法,在二叉树中求位于先序序列中第k个位置的结点的值。要求实现下列函数:TElemType PreOrder(BiTree bt, int k);/* bt is the root node of a binary linked list, *//* Preorder travel it and find the node whose *//*原创 2012-04-08 10:28:16 · 1080 阅读 · 0 评论 -
anyView 9.33
9.33③ 编写递归算法,从大到小输出给定二叉排序树中所有关键字不小于x的数据元素。要求你的算法的时间复杂度为O(log2n+m),其中n为排序树中所含结点数,m为输出的关键字个数。实现下列函数:void OrderOut(BiTree t, KeyType x, void(*visit)(TElemType));/* Output is to use visit(t-原创 2012-05-20 18:05:29 · 995 阅读 · 0 评论