예제 #1
0
파일: level_print.c 프로젝트: niraj17/work
int main(int argc, char *argv[])
{
	node_t n1,n2,n3,n4,n5;

	n1.data = 1;
	n1.left = &n2;
	n1.right = &n3;

	n2.data = 2;
	n2.left = &n4;
	n2.right = NULL;

	n3.data = 3;
	n3.left = NULL;
	n3.right = &n5;

	n4.data = 4;
	n4.left = NULL;
	n4.right = NULL;

	n5.data = 5;
	n5.left = NULL;
	n5.right = NULL;

	level_print(&n1);
}
예제 #2
0
파일: main.cpp 프로젝트: jonnyhsy/BST
int main(int argc, char* argv[])
{
	BSTree* root = NULL;
	uint vector[] = {15,6,18,3,7,17,20,2,4,13,9};
//	uint vector[] = {1,2,3,8};
	int i;
	const int length = sizeof(vector)/sizeof(uint);
//	BSTree* p;
	for(i = 0; i < length;i++)
		Insert_BST(&root,vector[i]);
	
	printf("InOrder_R: \n");
	InOrder_Traverse_R(root);	
	
//	printf("\nInOrder_I: \n");
//	InOrder_Traverse_I(root);
	printf("\nInOrder_I2: \n");
	InOrder_Traverse_I2(root);

//	printf("\nPreOrder_I: \n");
//	PreOrder_Traverse_I(root);
	printf("\nPreOrder_I2: \n");
	PreOrder_Traverse_I2(root);

	printf("\nPostOrder_I: \n");
	PostOrder_Traverse_I(root);
	printf("\nPostOrder_I2: \n");
	PostOrder_Traverse_I2(root);
	printf("\nPostOrder_I3: \n");
	PostOrder_Traverse_I3(root);

/*
	printf("\nMax value in BST: %u\n",MAX_BST(root)->key);
	printf("\nMin value in BST: %u\n",MIN_BST(root)->key);
	uint input;
*/	
/*	printf("\nplease input the value you want to search: ");
	scanf("%u",&input);
	BSTree* locate;
	locate = Search_BST_R(root,input);
	printf("\nSearch_R %u's value: %u\n",input,locate->key);
	locate = Search_BST_I(root,input);
	printf("Search_I %u's value: %u\n",input,locate->key);
*/
/*	while(input)
	{
		printf("\nplease input the value you want to delete: ");
		scanf("%u",&input);
		Delete_BST(root, input);
		printf("\nAfter delete %u:\n",input);
		InOrder_Traverse_R(root);
	}
*/

	level_print(root, sizeof(vector) / sizeof(uint));

	uint input;
	while(1)
	{
		printf("\nplease input the value: ");
		scanf("%u",&input);
		if (input == 0)
			break;
		SUCC_BST(root, input);
		PRE_BST(root, input);
//		InOrder_Traverse_R(root);
	}

	printf("\n");
	return 0;
}