Пример #1
0
int main (int argc, char*argv[])
{
   	if(argc!=3)
	{
		printf("More argument needed");
		return 0;
	}
	 
	FILE *input=fopen(argv[1],"r");
	FILE *search=fopen(argv[2],"r");
    	int insert,tree,treeNum=1;
	BST *root=NULL;
	rootList *rootl=NULL; 
	while(1)
	{
		fscanf(input,"%d",&insert);
		if(feof(input))break;
		
		if(insert==-1)
		{
			insert_rootList(&rootl,root);
                	root=NULL;
			treeNum++;
		}
		else
		{
			insert_BST(&root,insert,treeNum);
		}
		
	}
	
	printTrees(rootl);
	fclose(input);	
	fclose(search);
	//free_list(&rootl);
    return 0;

}
Пример #2
0
int main (int argc, char*argv[]){

	//If there are not enough command line arguments
	if(argc != 3)
	{
		printf("Not enough command line arguments. Exiting program...\n");
		return 1;
	}

	//Opens the files for reading
	FILE* input = fopen(argv[1], "r");
	FILE* search = fopen(argv[2], "r");

	//If the files DNE
	if(input == NULL || search == NULL)
	{
		printf("Not all files exist. Exiting program...\n");
		return 1;
	}

	BST* root = NULL;
	rootList* head = NULL;


	//Inserts values into the BST
	int insertValue, treeNum = 1;
	while(fscanf(input, "%d", &insertValue) != EOF)
	{
		if(insertValue == -1)
		{
			++treeNum;
			insert_rootList(&head, root);
			root = NULL;
		}
		else
		{
			insert_BST(&root, insertValue, treeNum);
		}

	}

	printTrees(head);

	//Prints out the trees and searches for values within the trees
	//Calls the free functions
	int searchValue;
	printf("Number %-7s%-7s%-7s\n", "Found", "Tree", "Level");
	while(fscanf(search, "%d", &searchValue) != EOF)
	{
		BFS(head, searchValue);
	}

	//Closes files
	fclose(input);
	fclose(search);

	//Calls the free functions
	free_list(&head);

    return 0;
}