41
5. 5. 设某棵二叉树的中序遍历序列为ABCD,后序遍历序列为BADC,则其前序遍历序列为
__________。
6. 6. 完全二叉树中第5层上最少有__________个结点,最多有_________个结点。
7. 7. 设有向图中不存在有向边
____________。
8. 8. 设一组初始记录关键字序列为(49,38,65,97,76,13,27,50),则第4趟直接选择排序结束
后的结果为_____________________________。
9. 9. 设连通图G中有n个顶点e条边,则对应的最小生成树上有___________条边。
10. 10. 设有一组初始记录关键字序列为(50,16,23,68,94,70,73),则将它们调整成初始堆
只需把16与___________相互交换即可。
四、算法设计题(20分)
1. 1. 设计一个在链式存储结构上统计二叉树中结点个数的算法。 2. 2. 设计一个算法将无向图的邻接矩阵转为对应邻接表的算法。
42
数据结构试卷(八)参考答案
一、选择题
1.C 2.C 3.C 4.B 5.B 6.C 7.B 8.C 9.A 10.A
二、判断题 1.对 2.错 3.对 4.错 5.错 6.对 7.对 8.对 9.对 10.对
三、填空题
1. 1. (49,13,27,50,76,38,65,97)
2. 2. t=(bitree *)malloc(sizeof(bitree)),bstinsert(t->rchild,k) 3. 3. p->next=s
4. 4. head->rlink,p->llink 5. 5. CABD 6. 6. 1,16 7. 7. 0
8. 8. (13,27,38,50,76,49,65,97) 9. 9. n-1 10. 10. 50
四、算法设计题
1. 1. 设计一个在链式存储结构上统计二叉树中结点个数的算法。
void countnode(bitree *bt,int &count) {
if(bt!=0)
{count++; countnode(bt->lchild,count); countnode(bt->rchild,count);} }
2. 2. 设计一个算法将无向图的邻接矩阵转为对应邻接表的算法。
typedef struct {int vertex[m]; int edge[m][m];}gadjmatrix;
typedef struct node1{int info;int adjvertex; struct node1 *nextarc;}glinklistnode; typedef struct node2{int vertexinfo;glinklistnode *firstarc;}glinkheadnode; void adjmatrixtoadjlist(gadjmatrix g1[ ],glinkheadnode g2[ ]) {
int i,j; glinklistnode *p;
for(i=0;i<=n-1;i++) g2[i].firstarc=0; for(i=0;i<=n-1;i++) for(j=0;j<=n-1;j++) if (g1.edge[i][j]==1) {
p=(glinklistnode *)malloc(sizeof(glinklistnode));p->adjvertex=j; p->nextarc=g[i].firstarc; g[i].firstarc=p;
p=(glinklistnode *)malloc(sizeof(glinklistnode));p->adjvertex=i; p->nextarc=g[j].firstarc; g[j].firstarc=p; } }
43
44

