示例#1
0
/*	================== buildHead =================
 This function creates the header structure that
 contains pointers to the tree and the hash table.
 It also calls other functions to read in the data
 file.
 Pre		pHeader - pointer to HEAD structure
 fileInput - name of the file
 Post		both the tree and the hash table are
 created.
 Return	pointer to create HEAD structure
 */
HEAD* buildHead (HEAD* pHeader, char* fileInput)
{
	//	Local Declarations
	DATA* newAirport;
    FILE* fpIn;
    
	//	Statements
    fpIn = fopen(fileInput, "r");
    if (!fpIn) {
        printf("Error opening input file\n");
        exit(101);
    }
    
    if ((pHeader = (HEAD*) malloc(sizeof(HEAD))))
    {
        pHeader->pHash = buildHash(2 * countLines(fileInput));
        pHeader->pTree = BST_Create(compareCode);
    }
    else{
        printf("Memory allocation error\n");
        exit(100);
    }
    
    while (getData(pHeader->pTree, fpIn, &newAirport)) {
        BST_Insert(pHeader->pTree, newAirport);
        insertHash(pHeader->pHash, newAirport);
    }
    
    return pHeader;
}	// buildHead
示例#2
0
int main(void){

   BST_TREE* BSTRoot;
   int* dataPtr;
   int dataIn = dataIn + 1;
   printf("Begin BST Demonstration\n");

   BSTRoot = BST_Create(compareInt);

   printf("Enter a list of positive integers\n");
   printf("Enter a negative number to stop.\n");

   do{
       printf("Enter a number:");
       scanf("%d", &dataIn);
       if (dataIn > -1){
          dataPtr = (int*) malloc (sizeof (int));
          if (!dataPtr){
              printf("Memory overflow");
              exit (100);
          }
          *dataPtr = dataIn;
          BST_Insert (BSTRoot, dataPtr);
        }

   } while (dataIn > -1);

   printf("\nBST contains:\n");
   BST_Traverse(BSTRoot, printBST);

   printf("\nEND BST Demonstration\n");
   return 0;
}
int main(){
	FILE *fp;
	fp = fopen("phones.txt", "r+");
	
	char name[30];
	char phone[20];

	BST_TREE* list;
	list = BST_Create (compareStu);

	// while(!feof(fp)){...}
	while(fscanf(fp, "%s %s", name, phone) == 2){
		// printf("%s, %s\n", name, phone);
		addStu(list, name, phone);
	};
	fclose(fp);

	char option = ' ';
	while ( (option = getOption ()) != 'Q'){
	    switch (option){
	        case 'A': 
	        		  printf("Input name: ");
	        		  scanf("%s", name);
	        		  printf("Input phone: ");
	        		  scanf("%s", phone);
	        		  addStu (list, name, phone);
	                  break;
	        case 'D': deleteStu (list);
	                  break;
	        case 'F': findStu (list);
	                  break;
	        case 'P': printList (list);
	                  break;
	      } // switch 
	   } // while 

	fp = fopen("phones.txt", "w");
	BST_Traverse (list, saveStu);
	fclose(fp);

	list = BST_Destroy (list);

	printf("\nEnd Student List\n");
	return 0;
}
示例#4
0
int main(){
	HASH *hash;
	D_LIST *list;
	int size = 30;
	int i = 0;
	BST_TREE *tree = BST_Create(cmpID);
	list = createDoublyList();
	hash = createHashTable(size);
	readFile(hash, list, tree);
	process(hash, list, tree);
	
	
	hash = freeData(hash);
	freeLinkedList(list);
	tree = BST_Destroy(tree);
    
	printf("\n\t\tEnd of the program!\n" );
#ifdef _MSC_VER
    printf( _CrtDumpMemoryLeaks() ? "No Memory Leak\n" : "Memory Leak\n");
#endif
	getch();
    
}