// MENU.CPP void Error_1_Menu(); Menu::Menu() { headlist = NULL; taillist = NULL; currentlist = NULL; _new_handler = &Error_1_Menu; } int Menu::DisplayMenu() { Crt.ClearScr(); cout << "\n\t----------------- CLASS LIST MENU -----------------\n\n"; cout << "\t\t 0.) Print Current List \n" << "\t\t 1.) Print All Lists \n" << "\t\t 2.) Create New Link List \n" << "\t\t 3.) Create New Stack List \n" << "\t\t 4.) Create New Queue List \n" << "\t\t 5.) Change to List ID Number \n" << "\t\t 6.) Delete Current List \n" << "\t\t 7.) Add Node to Current List \n" << "\t\t 8.) Append a Node in Current List \n" << "\t\t 9.) Delete Node from Current List \n" << "\t\t M.) Memory Check \n" << "\t\t E.) End this Program \n" << "\n Enter Choice ==>" ; Selection = Crt.GetChar(); return( Process( Selection ) ); } int Menu::Process( char S ) { char buffer[ 256 ]; int x; List *temp; cout << "\n\n"; switch( S ) { case '0': if(currentlist ) currentlist->Print(); else cout << " NO LISTS ARE CREATED! \n"; break; case '1': if( headlist ) { temp = headlist; while( temp ) { temp->Print(); temp = temp->Get_Right_List(); } } else cout << " NO LISTS ARE CREATED! \n"; break; case '2': if( ! headlist ) { temp = new LinkList; headlist = temp; taillist = headlist; currentlist = headlist; } else { temp = new LinkList; currentlist = temp; currentlist->ConnectTo( taillist ); taillist = currentlist; } cout << " New Link List Created \n"; break; case '3': if( ! headlist ) { headlist = new Stack; taillist = headlist; currentlist = headlist; } else { currentlist = new Stack; currentlist->ConnectTo( taillist ); taillist = currentlist; } cout << " New Stack Created \n"; break; case '4': if( ! headlist ) { headlist = new Queue; taillist = headlist; currentlist = headlist; } else { currentlist = new Queue; currentlist->ConnectTo( taillist ); taillist = currentlist; } cout << " New Queue Created \n"; break; case '5': int found = 0; if( headlist ) { Crt.ClearScr(); temp = headlist; while( temp ) { temp->Print(); temp = temp->Get_Right_List(); } temp = headlist; cout << " Enter List ID to Change to ==>"; cin >> x; while( temp ) { if( temp->List_ID() == x ) { currentlist = temp; found = 1; break; } else temp = temp->Get_Right_List(); } if( found ) currentlist->Print(); else cout << " LIST NOT FOUND ! \n"; } else cout << " NO LISTS ARE CREATED! \n"; break; case '6': if( currentlist ) { x = currentlist->List_ID(); currentlist->Disconnect(); if( headlist == currentlist ) headlist = currentlist->Get_Right_List(); if( taillist == currentlist ) taillist = currentlist->Get_Left_List(); delete currentlist; currentlist = headlist; cout << " LIST #" << x << " DELETED "; } else cout << " NO LISTS ARE CREATED ! \n"; break; case '7': if( currentlist ) { Crt.ClearScr(); currentlist->Print(); cout << " Enter String ==>"; cin >> buffer; cout << "\n"; switch( *(currentlist->List_Name()) ) { case 'L': currentlist->Insert( buffer ); break; case 'S': currentlist->Push( buffer ); break; case 'Q': currentlist->EnQueue( buffer ); break; } } else cout << " NO LISTS ARE CREATED! \n"; break; case '8': if( currentlist ) { currentlist->Print(); cout << " Enter Node # to Append ==>"; fflush( stdin ); cin >> x; cout << " Enter String ==>"; fflush( stdin ); cin >> buffer; cout << "\n"; currentlist->Append_Node( x, buffer ); } else cout << " NO LISTS ARE CREATED! \n"; break; case '9': if( currentlist ) { currentlist->Print(); switch( *(currentlist->List_Name()) ) { case 'L': cout << " Enter Node # to Delete ==>"; fflush( stdin ); cin >> x; currentlist->Remove( x ); break; case 'S': currentlist->Pop(); break; case 'Q': currentlist->DeQueue(); break; } } else cout << " NO LISTS ARE CREATED! \n"; break; case 'M': case 'm': Crt.MemChk(); break; case 'E': case 'e': cout << " End Program? ( Y or N ) "; if( Crt.GetChar() == 'Y' || Crt.GetChar() == 'y' ) { cout << "\n\n"; Crt.Pause(); return( 0 ); } cout << "\n"; break; } cout <<"\n"; Crt.Pause(); return( 1 ); } void Error_1_Menu() { cerr << "\n\n\t MEMORY ERROR: NEW in Menu.CPP. \n"; cout << "\n\tStack: " << stackavail() << " Stack Pointer: " << _SP; cout << " Core Left: " << coreleft() << "\n"; exit ( 1 ); } // MENU.CPP