摘要: 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 the dencendant of node ‘v’, *//* then return ‘TRUE’ else return ‘FALSE’. *//* L[i] is the left child of the i_th node 阅读全文
posted @ 2011-05-15 22:59 hlb430 阅读(4252) 评论(0) 推荐(1)
摘要: 5.18⑤ 试设计一个算法,将数组A中的元素A[0..n-1]循环右移k位,并要求只用一个元素大小的附加存储,元素移动或交换次数为O(n)。要求实现以下函数:void Rotate(Array1D &a, int n, int k);一维数组类型Array1D的定义:typedef ElemType Array1D[MAXLEN];void Rotate(Array1D &a, int n, int k) /* a[n] contains the elements, */ /* rotate them right circlely by k sits */ { ... 阅读全文
posted @ 2011-05-15 22:55 hlb430 阅读(5366) 评论(0) 推荐(0)
摘要: 4.10③编写对串求逆的递推算法。要求实现以下函数:voidReverse(StringType&s);/*Reversesbyiteration.*/StringType是串的一个抽象数据类型,它包含以下6种基本操作:voidInitStr(StringType&s);//初始化s为空串。voidStrAssign(StringType&t,StringTypes);//将s的值赋给t。s的实际参数是串变量。intStrCompare(StringTypes,StringTypet);//比较s和t。若s>t,返回值>0;若s=t,返回值=0;若s< 阅读全文
posted @ 2011-05-15 10:55 hlb430 阅读(4244) 评论(1) 推荐(0)