void printList (BST_TREE* list){ // Statements printf("\nStudent List:\n"); BST_Traverse (list, processStu); printf("End of Student List\n"); return; } // printList
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; }
/* ================== getOption ================= This function reads in the user's desired chose of operation. Calls upon other functions to perform the procedure. Pre pHeader - pointer to HEAD structure Post Return */ void getOption (HEAD* pHeader) { // Local Declarations char command; DATA target; DATA* airport = NULL; int i; // Statements while ((command = menu()) != 'Q') { switch (command) { case 'A': if (addAirport(pHeader)) { while (checkHash(pHeader->pHash) == 1) { pHeader->pHash = upsizeHash(pHeader->pHash); } printf ("\n Succesfully added data.\n\n"); } break; case 'D': printf("Enter the airport code: "); scanf(" %s", target.arpCode); if (deleteHash (pHeader, target)) { while (checkHash(pHeader->pHash) == -1) { pHeader->pHash = downsizeHash(pHeader->pHash); } printf ("\n Succesfully deleted data.\n\n"); } break; case 'F': printf("Enter the airport code: "); scanf(" %s", target.arpCode); // fix sensitive input cases for (i = 0; i < strlen(target.arpCode); i++) { target.arpCode[i] = toupper(target.arpCode[i]); } airport = findHash(pHeader->pHash, &target); if (airport != NULL) { processScreen(airport); } else printf("No airport exists\n"); break; case 'L': printHash(pHeader->pHash); break; case 'K': BST_Traverse(pHeader->pTree, processScreen); break; case 'P': printTree(pHeader->pTree->root, 0); printf("\n"); break; case 'W': outputFile (pHeader->pHash); break; case 'E': efficiency(pHeader->pHash); break; case 'H': pHeader->pHash = hashDemo(pHeader->pHash); break; default: printf("Invalid choice. Choose again\n"); break; } } return; } // getOption