1、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
2、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 一>lef
3、t, 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 3 x 2. 456 一*十