Server IP : 172.16.15.8 / Your IP : 52.15.72.229 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/jmsanchez/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
#include <iostream> //#include <conio> using namespace std; const int MAX=50; class List { int length; string data[MAX]; public: List () { length = 0; } int Length () const { return length; } bool IsFull () const { return ( length == MAX ); } bool IsEmpty () const { return ( length == 0 ); } void Print () const { for ( int k=0; k<length; k++ ) cout << data[k] << ' '; cout << endl; } void Insert ( string str1 ) { data[ length ] = str1; length ++; } bool IsPresent ( string str1 ) const { bool done = false; for ( int k=0; k<length && ! done; k++ ) if ( data[k] == str1 ) done = true; return done; } void SelSort ( ); };//37 void List :: SelSort ( ) { string temp; // for swapping int passCount; int minIndex; // hold the index of the minimum for ( passCount=0; passCount<length-1; passCount ++ ) { minIndex = passCount; for ( int k=passCount+1; k<length; k++ ) { if ( data[minIndex] > data[k] ) minIndex = k; } temp = data[minIndex]; data[minIndex] = data[passCount]; data[passCount] = temp; } }//56 void menu (); void process ( char, List& ); int main() { List myList; char ch; menu(); cin >> ch; while ( tolower(ch) != 'q' ) { process(ch, myList); menu(); cin >> ch; } getchar(); return 0; } void menu () { // clrscr(); cout << "i insert a word\n"; cout << "f find a word\n"; cout << "p print the lisr\n"; cout << "s sort the list\n"; cout << "q quit the operation\n"; cout << "\nYou Choose: "; } void process ( char ch, List& myList )//88 { string datum; switch ( tolower(ch) ) { case 'i': cout << "Input an integer: "; cin >> datum; myList.Insert(datum); cout << "The list is: "; myList.Print(); cout << "Type any key to continue...\n"; getchar(); break; case 's': myList.SelSort(); cout << "The list is: "; myList.Print(); cout << "Type any key to continue...\n"; getchar(); break; case 'p': cout << "The list is: "; myList.Print(); cout << "\n\nType any key to continue...\n"; getchar(); break; case 'f': cout << "Input an item to be found: "; cin >> datum; if ( myList.IsPresent(datum) ) cout << datum << " is in the list.\n"; else cout << datum << " isn't in the list.\n\n"; cout << "\n\nType any key to continue...\n"; getchar(); break; default: cout << "\nInvalid input.\n"; cout << "\n\nType any key to continue...\n"; getchar(); } return; }