// ----------------------------------------------------------------------------- // DataPack class: an array plus its management information. // Implementation file for all DataPack programs. datapack.cpp // Created by Alice Fischer on Mon August 23, 2009 // ----------------------------------------------------------------------------- #include "datapack.hpp" // --------------------------------------------------------------------- // Read (from user) name of input file and open it. // Read up to max items from input stream and store in array. void DataPack::readData() { char filename[80]; // For name of input file cout << "Enter name of data file to be searched: "; cin.getline( filename, 80 ); ifstream infile( filename ); if (! infile) fatal( " Error: couldn't open input %s\n", filename ); BT* cursor = store; // Scanning pointer, set to start of array. BT* end = store + max; // An off-board sentinel for( ; cursor> *cursor; if( ! infile.good() ) break; // Quit for bad data or for end of file. } n = cursor-store; // Actual # of items read. } // --------------------------------------------------------------------- // Print the data from the array. void DataPack :: printData( ostream& out ) { for( int k=0; k store; --hole ) { if ( *(hole-1) <= newcomer ) break; // Insertion slot is found. *hole = *(hole-1); // Move item 1 slot rightward. } *hole = newcomer; } }