Example #1
0
struct NODE *  Create_Tree (char Info, struct NODE *Node)
{

	if (Node == NULL)
	{
		Node = (struct NODE *) malloc(sizeof(struct NODE));
		Node->Info = Info;
		Node->Left_Child = NULL;
		Node->Right_Child = NULL;
		return (Node);
	}

	/* Test for the left child */

	if (Info < Node->Info)

		Node->Left_Child = Create_Tree (Info, Node->Left_Child);

	else

		/*  Test for the right child */

		if (Info > Node->Info)

			Node->Right_Child = Create_Tree (Info, Node->Right_Child);
	return(Node);
}
Example #2
0
int  main()
{
	int Number = 0;
	char Info ;
	char choice;
	int depth;
	struct NODE *T = (struct NODE *) malloc(sizeof(struct NODE));
	T = NULL;
	//printf("\n Input choice 'b' to break:");
	//choice = getchar();

	while(1)
	{
		fflush(stdin);
		printf("\n Input information of the node: ");
		scanf("%c", &Info);
		if(Info=='Z') break;
		T=Create_Tree(Info, T);
		printf("%x\n",T);		
Number++;
		fflush(stdin);
		//printf("\n Input choice 'b' to break:");
		//choice = getchar();
	}
	printf("\n Number of elements in the list is  %d", Number);
	printf("\n Tree is \n");
	Output(T, 1,a);

	depth = Depth(T, 0);
	printf("\n Depth of the above tree is:  %d", depth);

return 0;
}
Example #3
0
int  main()
{
	int Number = 0;
	int  Info ;
	//char choice;
	//int depth;
	struct NODE *T = (struct NODE *) malloc(sizeof(struct NODE));
	T = NULL;
	printf("\n Input choice 'b' to break:");
	//choice = getchar();

	while(Info!=0)
	{
		//fflush(stdin);
		printf("\n Input information of the node: ");
		scanf("%d", &Info);
		T = Create_Tree(Info, T);
		Number++;
		/*fflush(stdin);
		printf("\n Input choice 'b' to break:");
		choice = getchar();*/
	}
	printf("\n Number of elements in the list is  %d", Number);
	printf("\n Tree is \n");
	Output(T, 1);


	
return 0;
}
Example #4
0
void dictionary()
{
	char newtime[100];
	FILE* pf3 = fopen("log.txt","a+");
	int func_choice;
	TREETYPE *root = NULL;
	root = Create_Tree(root);
	ELEMTYPE word[WN];
	func_choice=dict_memu();//功能选择
	int skip;
	char ch[10] = "q";
	switch(func_choice)
	{
		case 1:
		{
			printf("请输入要查找的内容\n");
			scanf("%s", word);
			skip=Search_Word(root,word);
			strcpy(newtime , timeinfo());
			fprintf(pf3,"%s",newtime);
			fprintf(pf3,"%s","搜索词条: ");
			fprintf(pf3,"%s, ",word);
			if(skip==0)
			{
				fprintf(pf3, "%s\n", "不存在");
				fseek(pf3,0,SEEK_END);
				strcpy(ch, "q");
				while(NOTNEED)
				{
					printf("是否添加到字典?(y/n)\n");
					scanf("%s", ch);
				}
				if(0 == strcmp(ch, "y"))
					goto ADDWORD;
				else
				{
					printf("%s","\033[1H\033[2J");
					dictionary();
				}
			}
			if(skip==1)
			{
				fprintf(pf3,"%s\n","成功");
				fseek(pf3,0,SEEK_END);
				printf("查找结束,按任意键继续....\n");
				setbuf(stdin, NULL);
				getchar();
				printf("%s","\033[1H\033[2J");
				dictionary();
			}
			break;
		}
		case 2: 
		{
			printf("请输入要增加的词条\n");
			
			scanf("%s", word); 
ADDWORD:
			strcpy(newtime , timeinfo());
			fprintf(pf3,"%s",newtime);
			fprintf(pf3,"%s","增加词条: ");
			fprintf(pf3,"%s, ",word);
			skip=Add_Word(root,word);
			if (-1==skip)
			{
				fprintf(pf3, "撤销操作\n");
				fseek(pf3, 0, SEEK_END);
				printf("按任意键继续....\n");
				getchar();
			}
			if(skip==0)
			{
				fprintf(pf3, "%s\n", "已存在");
				fseek(pf3,0,SEEK_END);
				strcpy(ch, "q");
				while(NOTNEED)
				{
					printf("此单词已存在,是否进行修改?(y/n)\n");
					printf("%s\n", word);
					Search_Word(root, word);
					scanf("%s", ch);
				}
				if (0 == strcmp(ch, "y"))
					goto MODIWORD;
				
			}
			if(skip==1)
			{
				fprintf(pf3,"%s\n","成功");
				fseek(pf3,0,SEEK_END);
				sgn_save = 1;
				printf("添加成功,按任意键继续....\n");
				setbuf(stdin, NULL);
				getchar();
			}
			printf("%s","\033[1H\033[2J");
			dictionary();
			break;
		}
		case 3:
		{
			printf("请输入要删除的词条\n");
			scanf("%s", word);
			strcpy(newtime , timeinfo());
			fprintf(pf3,"%s",newtime);
			fprintf(pf3,"%s","删除词条: ");
			fprintf(pf3,"%s, ",word);
			skip = Dele_Word(root, word);
			if (skip == 1)
			{
				fprintf(pf3,"%s\n","成功");
				fseek(pf3,0,SEEK_END);
				sgn_save = 1;
				printf("删除成功,按任意键继续...\n");
			}
			else
			{
				fprintf(pf3,"%s\n","不存在");
				fseek(pf3,0,SEEK_END);
				printf("词条不存在,按任意键继续...\n");
			}
			setbuf(stdin, NULL);
			getchar();
			printf("%s","\033[1H\033[2J");
			dictionary();
			break;
		}
		case 4:
		{
			printf("请输入要修改的词条\n");
			scanf("%s", word);
			Search_Word(root, word);
MODIWORD:
			strcpy(newtime , timeinfo());
			fprintf(pf3,"%s",newtime);
			fprintf(pf3,"%s","修改词条: ");
			fprintf(pf3,"%s, ",word);
			skip = Modi_Word(root, word);
			if (skip == 1)
			{
				fprintf(pf3,"%s\n","成功");
				fseek(pf3,0,SEEK_END);
				sgn_save = 1;
				printf("修改成功,按任意键继续....\n");
			}
			else
			{
				fprintf(pf3,"%s\n","不存在");
				fseek(pf3,0,SEEK_END);
				strcpy(ch, "q");
				while(NOTNEED)
				{
					printf("是否添加?(y/n)\n");
					scanf("%s", ch);
				}
				if (0 == strcmp(ch, "y"))
					goto ADDWORD;
				else
				{
					printf("%s","\033[1H\033[2J");
					dictionary();
				}
			}
			setbuf(stdin, NULL);
			getchar();
			printf("%s","\033[1H\033[2J");
			dictionary();
			break;
		}
		case 5:
		{
			strcpy(ch, "q");
			while (NOTNEED)
			{
				printf("是否覆盖已有词库?(y/n)\n");
				scanf("%s", ch);
			}
			if (strcmp(ch, "y") == 0)
			{
				strcpy(newtime , timeinfo());
				fprintf(pf3,"%s",newtime);
				fprintf(pf3,"%s","保存词库: ");
				fprintf(pf3,"%s, ",dictPath);
				if(Overwrite_Dict(TMPPATH, dictPath)==1)
				{
					fprintf(pf3,"%s\n","成功");
					fseek(pf3,0,SEEK_END);
					printf("保存成功,按任意键继续....\n");
					sgn_save = 0;
				}
				else
				{
					fprintf(pf3,"%s\n","失败");
					fseek(pf3,0,SEEK_END);
					printf("抱歉,保存失败,按任意键继续....\n");
				}
			}
			else
			{
				fprintf(pf3, "%s\n", "撤销操作");
				fseek(pf3, 0 , SEEK_END);
				printf("已取消操作,按任意键继续....\n");
			}
			setbuf(stdin, NULL);
			getchar();
			printf("%s","\033[1H\033[2J");
			dictionary();
			break;
		}
		case 6:
		{
			char ch[10] = "q";
			if (sgn_save)
			{
				while (NOTNEED)
				{
					printf("文件已修改,是否保存?(y/n)\n");
					scanf("%s", ch);
				}
				if (0 == strcmp(ch, "y"))
				{
					strcpy(newtime , timeinfo());
					fprintf(pf3,"%s",newtime);
					fprintf(pf3,"%s","保存词库: ");
					fprintf(pf3,"%s, ",dictPath);
					if(Overwrite_Dict(TMPPATH, dictPath)==1)
					{
						fprintf(pf3,"%s\n","成功");
						fseek(pf3,0,SEEK_END);
						printf("保存成功,按任意键继续....\n");
					}
					else
					{
						fprintf(pf3,"%s\n","失败");
						fseek(pf3,0,SEEK_END);
						printf("抱歉,保存失败,按任意键继续....\n");
					}
					setbuf(stdin, NULL);
					getchar();
				}
				sgn_save = 0;
			}
			printf("%s","\033[1H\033[2J");
			main_menu();
		}
		default: break;
	}
}