Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    struct node23 *tree;
    int num = 0;

    if (argc != 5)
    {
        perror(argv[1]);
        return -1;
    }

    FILE *fp;
    fp = fopen(argv[4], "r");

    int baseX = atoi(argv[1]);
    int baseY = atoi(argv[2]);
    int baseZ = atoi(argv[3]);

    double dis;
    int x, y, z;

    tree = NULL;

    while (fscanf(fp, "(%d, %d, %d)\n", &x, &y, &z) == 3)
    {
        num++;
        dis = distance(baseX, x, baseY, y, baseZ, z);

        if (insert23(dis, x, y, z, &tree) == NULL)
        {
            //fprintf(stderr, "Item (%d,%d,%d) is alread in the tree\n", x, y, z);
            num--;
        }
        //fprintf(stderr, "Checking Tree - tree index = %d value = %.1f\n", num, dis);

        if (!valid23(tree))
        {
            print_tree23(tree, 0);
            return -1;
        }
    }

    print_tree23(tree, 0);
    //fprintf(stderr, "All trees correct\n");
    free23(tree);
    fclose(fp);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
        int i = 0;
		char select;
		int insert;
        tree23* tree = makeTree23();
		while(1){
		printf("[i]Insert [d]Delete [p]Print [f]Find [q]quit\n");
		printf("Select : ");
		scanf("%c", &select);
		fflush(stdin);
		
		switch(select){
		case 'i':
			printf("Input : ");
			scanf("%d", &insert);
			fflush(stdin);
			insert23(tree, insert);
			break;
		case 'd':
			printf("Delete : ");
			scanf("%d", &insert);
			fflush(stdin);
			delete23(tree, insert);
			break;
		case 'p':
			printf("***** Print *****\n");
			print23(tree);
			printf("\n");
			break;
		case 'f':
			printf("Find : ");
			scanf("%d", &insert);
			fflush(stdin);
			if(search23(tree->root, insert))
				printf("Exist : %d \n", insert);
			else
				printf("Not Exist\n");
			break;
		case 'q':
			return 0;
		}
		}
}