typedef struct BinNode{ int data;
struct BinNode* leftchild, * rightchild; }BinNode, *BinTree;
void InitBinTree(BinTree &root) //初始化二叉树root {
root=Null; }
void DestroyBinTree(BinTree &root) //销毁二叉树root {
if (root == NULL) return;
DestroyBinTree(root->leftchild); DestroyBinTree (root->rightchild); free(root); }
int countNodes1(BinTree &root) //计算二叉树root中度为1的结点数 {
){ if(root-> leftchild!=NULL && root-> rightchild!=NULL)
___② else if(root-> leftchild==NULL && ____else if (root-> leftchild!=NULL && ) __}
return 0; }
5
数据结构第二次作业答案(C语言版)-07
2. 下面是起泡排序算法的实现。试在程序的每一划线部分填入一条语句或表达式,以使该算
法在发现数据有序时能及时停止。
void BubbleSort(int datalist[], int size) //要排序的数据存放在数组datalist[]中,元素个数=size {
int exchange,i,j,temp; i=1;
exchange=1;
while(i<size && ___ {
_____⑨ for(j=size-1;j>=i; j--)
if(datalist[j-1]>datalist[j])
{
temp=datalist[j-1]; datalist[j-1]=datalist[j]; datalist[j]=temp;
____}
i++; } }
6

