正在加载图片...
int search(s table L, Key Type K) Lelem[L length+]=K while(K! elem 1+ return( 1%(L length+1)) 0.将折半查找的算法改写为递归算法 int BiSearch(s table L, int low, int high, Key Type x) if (low>high) return(o) mid=(low+high )/2 if(X==Lelem(mid. key) return(mid) else if(X<L elem[mid]. key) BiSearch(L,low, mid-1, x) Else BiSearch(L, mid+l, high, x) I在平衡二叉排序树的每个结点中增设一个1size域,其值为它的左子树中的结点数加1。试写以时 间复杂度为o(1og2n)的算法,确定树中第k小的结点的位置。 typedef struct BTNode Elemtype data int lsize struct BTNode *lchild *rchild BTNode *BiTree BiTree index(bitree t, int k) if(t-NULL return ( NULL) if(t->lsize==K) return(t else if(t->lsize>k)int search(S_table L , KeyType K) { L.elem[L.length+1] = K ; i=1; while (K! =L.elem[i]) i++ ; return ( i%(L.length+1)) ; } ⒑将折半查找的算法改写为递归算法。 int BiSearch(S_table L, int low, int high,KeyType x) { if (low>high) return(0); mid=(low+high)/2; if (x= =L.elem[mid].key) return(mid); else if (x<L.elem[mid].key) BiSearch(L,low,mid-1,x); Else BiSearch(L,mid+1,high,x); } ⒒在平衡二叉排序树的每个结点中增设一个 lsize 域,其值为它的左子树中的结点数加 1。试写以时 间复杂度为 O(log2n)的算法,确定树中第 k 小的结点的位置。 typedef struct BTNode{ Elemtype data; int lsize; struct BTNode *lchild , *rchild; }BTNode ,*BiTree; BiTree index(BiTree t, int k) { if (t==NULL) return(NULL); if (t->lsize= =K) return(t); else if (t->lsize>K)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有