예제 #1
0
void creattree(TREE *T){
	int d;
	scanf("%d",&d);
	if(d==0) (*T)=NULL;
	else{
		if(!((*T)=(TREE)malloc(sizeof(Tree)))) exit(0);
		(*T)->data=d;
		creattree(&((*T)->left));
		creattree(&((*T)->right));
	}
}
예제 #2
0
int binatTreeMain(){
	TREE T;
	int choice;
	char c='y';
	printf("请输入带空二叉树先序遍历序列(0表示空节点),例如3个元素的二叉树输入为\n");
    printf(" 1 2 0 0 3 0 0 (1为根结点):");
	creattree(&T);
	while(c=='Y'||c=='y'){
	choice=menu();
	switch(choice){
	case 11:printf("递归法前序遍历:");pretraverse1(T);break;
	case 12:printf("非递归法前序遍历:");pretraverse2(T);break;
	case 21:printf("递归法中序遍历:");intraverse1(T);break;
	case 22:printf("非递归法中序遍历:");intraverse2(T);break;
	case 3:printf("递归法后序遍历:");posttraverse1(T);break;	
	case 41:outdegree1(T);
			printf("出度为0的节点数目:%d\n",n0);
	        printf("出度为1的节点数目:%d\n",n1);
	        printf("出度为2的节点数目:%d\n",n2);break;
	case 42:outdegree2(T);break;	
	case 5:floortraverse(T);break;
	case 6:printf("\n此二叉树高度为:%d",hight(T));break;
	case 7:exchange(&T);intraverse1(T);break;
	}
    printf("\n是否继续?(Y/N):");
	fflush(stdin);
	scanf("%c",&c);
	system("cls");
	}
}
예제 #3
0
파일: tree.cpp 프로젝트: khiemnv/algorithms
void main()
{int n;float**m;
bbb*a0;
clrscr();
input(m,&n);
creattree(a0,m,n);
readtree(a0,m,n);
output(m,n);
getch();
}