Пример #1
0
void insert(char p,char c)
{
	char s;
	if(!(isalpha(c)||('0'<=c&&c<='9')))
	{
		printf("\nonly alphabats & number is allowed!!!\n");
		return;
	}
	struct neel *f;
	f=travers(p);
	if(f==NULL)
	{
		printf("\n%c not found!!",p);
		return;
	}
neel:printf("\nwhere you want to insert\n1.left\n2.right\n");
	s=getche();
	if(s=='1')
	{
		if(f->l!=NULL)
		{
			printf("\nleft link of %c is not available..\n",p);
			return;
		}
		else
		f->l=(struct neel *)malloc(sizeof(struct neel));
		f->l->x=c;
		f->l->l=NULL;
		f->l->r=NULL;
	}
	else if(s=='2')
	{
		if(f->r!=NULL)
		{
			printf("\nright link of %c is not available..\n",p);
			return;
		}
		else
		f->r=(struct neel *)malloc(sizeof(struct neel));
		f->r->x=c;
		f->r->l=NULL;
		f->r->r=NULL;
	}
	else
		goto neel;
	printf("\n%c is inserted..\n",c);
}
Пример #2
0
void main()
{
	char c,d;
	printf("enter root node..");
scanr:c=getche();
	if(!(isalpha(c)||('0'<=c&&c<='9')))
	{
		printf("\nonly alphabats & number is allowed!!!\n");
		goto scanr;
	}
	root=(struct neel *)malloc(sizeof(struct neel));
	root->x=c;
	root->l=NULL;
	root->r=NULL;
	for(;1;)
	{
		printf("\nmenu\n1.insert\n2.inorder travers\n3.preorder travers\n4.postorder travers\n0.exit");
		printf("\nenter your choice..\n");
		switch(getche())
		{
			case '1':printf("\nenter parent node & new node..");
					c=getche();
					printf("  ");
					d=getche();
					insert(c,d);
					break;
			case '2':travers('#');break;
			case '3':printf("\nPREORDER SEQUENCE :- ");
					preorder(root);
					break;
			case '4':printf("\nPOSTORDER SEQUENCE :- ");
					postorder(root);
					break;
			case '0':return;
					break;
			default:
				printf("wrong choice...");	
		}	
	}
getch();
}
Пример #3
0
int main(int argc, char * argv[]) {
	struct a_table translator;
	FILE * dict = 0, * in = 0, * out = 0;

	LOG("This is a debug version!");

	if (argc == 1) {
		printf("Changes a text using a dictionary by replacing each occurrence of a word in the dictionary with the proper image word.\n"
			"Syntaxis: replacer dict input output\n"
			"dict is a text file with word pairs\n"
			"input is the file to be changed\n"
			"output is the result file.\n");
		return 0;
	}

	if (argc != 4) {
		printf("Invalid argumets! Extected 3, provided: %d.\n", argc - 1);
		return 1;
	}

	dict = fopen(argv[1], "r");
	if (dict == 0) {
		printf("Unable to open the dict file. Argument value is %s.\n", argv[1]);
		return 1;
	}

	/* initialize the allocator */
	mem_init();

	/* initialize the table */
	a_create_n(&translator, INIT_SIZE);

	/* step1: create a trie */
	create_trie(&translator, dict);

	fclose(dict);

	/* step2: create the full automaton */
	add_fail_links(&translator);

	in = fopen(argv[2], "rb");
	if (in == 0) {
		printf("Unable to open the input file. Argument value is %s.\n", argv[2]);
		fclose(dict);
		a_free(&translator);
		mem_fin();
		return 1;
	}

	out = fopen(argv[3], "wb");
	if (out == 0) {
		printf("Unable to open the output file. Argument value is %s.\n", argv[3]);
		fclose(in);
		fclose(dict);
		a_free(&translator);
		mem_fin();
		return 1;
	}

	/* finally we are going to use the automaton */
	travers(&translator, in, out);

	fclose(in);
	fclose(out);

	/* finalize the table */
	a_free(&translator);

	/* finalize the allocator */
	mem_fin();
}