资源描述
2、V01dAC(List&L)
InitList(L);
InsertRear (L;25);
InsertFront(L, 50);
IntaL4] = (5, 8, 12, 15, 36};
for(inti=0; i<5; i++)
if (a[i] %2= =0) InsertFront (L, a[i]);
elselnsertRear(L, a[i]):
}
该算法被调用执行后,得到的线性表L为:
五、算法填空,在画有横线的地方填写合适的内容。
1、己知二叉树中的结点类型BinTreeNode定义为:
structBinTreeNode(ElcmType data; BinTreeNode*left, bright};
其中data为结点值域,left和right分别为指向左、右子女结点的指针域。下 面函数的功能是返回二叉树BT中值为x的结点所在的层号,请在划有横线的地方填写 合适内容。
Int NodeLevel(BinTreeNode * BT, ElemType X)
(
if(BT: = NULL)return 0;/ / 空树的层号为 0
else if (BT —>data==X)return 1: / / 根结点的层号为 1
/ /向子树中查找x结点
else(
int cl=NodeLevel (BT 一>left, X):
if(cl> = l)return cl + 1;
int c2=;
if——;
/ /若树中不存在X结点则返回。
else return 0;
}
}
2、从一维数组A[n)中二分查找关键字为K的元素的递归算法,若查找成功则返 回对应元素的下标,否则返回一 1。
IntBinsch(ElemTypeA[], Intlow, int high, KeyTypeK)
(
if (low< = high)
(
int mid= (low+high) / 2;
if (K==A[mid]. key);
else if (K<A[mid]. key);
else ;
}
else return——1;《数据结构》自测题部分参考答案
一、单选题
1、 C 2、 A 3、 B 4、 B 5、 B
二、填空题。
1、值(或data) 子表指针(或sublist)
2、邻接矩阵 邻接表边集数组(次序无先后)
3、顺序结构、链接结构、索引结构、散列结构
4、小于大于(或大于等于)
5、0(n2)0(e)
6、518
7> 3 x 2. 456 一*十
展开阅读全文