/******************************************************* Proj5Aux.cpp CMSC-341 Spring 2004 Project5 Spencer Shimko, Section 001, sshimko1 Created: 28 April 2004 Current: 06 May 2004 Auxillary header implement a Interval Heap based on a Binary Heap I have read and I understand the course policy on cheating. By submitting the following program, I am stating that the program was produced by my individual effort. *********************************************************/ using namespace std; #include #include #include #include #include "IntervalHeap.h" /* * parse the input file * Params: input file to parse */ bool parseIFile ( const char * iFile, queue & cmdQ ){ string line; // open/test file ifstream sFile( iFile, ios::in ); // if file did not open properly display error and die if ( !sFile ){ return false; } while ( getline ( sFile, line ) ) cmdQ.push(line); return true; } /* * run command * Params: IntervalHeap and String to run */ void run ( IntervalHeap &IH, const char* c ){ // command char* cmd = (char*) c; // print current command cout << "\nCOMMAND: " << cmd << endl; // convert them to a standard lower case for ( int index = 0; cmd[index]; index++ ){ cmd[index] = tolower ( cmd[index] ); } if ( strstr( cmd, "insert " ) != NULL ) { // tokenize and grab integer to insert strtok ( cmd, " " ); int i = atoi ( strtok ( NULL, "\n" ) ); // insert int into heap IH.insert ( i ); return; } else if ( strstr ( cmd, "print" ) != NULL ){ //print heap IH.print ( ); return; } else if ( strstr ( cmd, "findmin" ) != NULL ){ // print minimum value cout << " The minimum value in the heap is " << IH.findMin ( ) << "." << endl; } else if ( strstr ( cmd, "findmax" ) != NULL ){ // print maximum value cout << " The maximum value in the heap is " << IH.findMax ( ) << "." << endl; } else if ( strstr ( cmd, "deletemin" ) != NULL ){ // delete smallest value IH.deleteMin ( ); } else if ( strstr ( cmd, "deletemax" ) != NULL ){ // delete largest value IH.deleteMax ( ); } }