int main( )
{
   
    //create queue
    BinQueuePlusPlus ourQueue;
    //tells user findings
    cout<<"Comparison count after insertion: " <<ourQueue.getComparCount()<<endl;   
    cout<<"Assignment count after insertion: " <<ourQueue.getAssignCount()<<endl;

    //run tasks
    runDeleteTask(ourQueue);
    runFindTask(ourQueue);
    runRemoveTask(ourQueue);
    
    
    
    
    return 0;
}
void runRemoveTask(BinQueuePlusPlus& ourTree)
{
    cout<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<"**                 Running Remove Task                      **"<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<endl;
    

    string input;
    for(int i = 1; i<=5; i++){
        
        //prompt user for key
        cout<<i<<") Please enter a key for removal: ";
        cin>>input;
        
        //check if key is in queue
        if (ourTree.contains(input) == false)
        {
            cout<<"KEY : "<<input<<"  does not exist in queue"<<endl;
        }
        else{
            //check if the remove was successful
            if(ourTree.remove(input))
            cout<<"KEY : "<<input<<" : checked & successfully deleted"<<endl;
            
            else
                cout<<"unsuccessful removal"<<endl;
        }
        
        cout<<endl;
    }//end loop
    
    cout<<"Remove Task has ended..." <<endl;
       
}
void runDeleteTask(BinQueuePlusPlus &ourQueue){
    
    cout<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<"**                   Running Delete Task                    **"<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<endl;
    
    cout<< "The following item has been deleted from the queue: "<<endl;
    for(int x = 1; x <= 10; x++){
        //run the delete min 10 times
        cout<<  ourQueue.deleteMin()<<endl;
    }
    
    cout<< "Test the deleteMin() operation has been completed."<<endl;
}
示例#4
0
int main(){
	string line;			
	BinQueuePlusPlus coolBin;
	
	ifstream textFile("words.txt");							//open textfile

	if(textFile.is_open()){
		int counter = 0;
		while(getline(textFile, line)){						//populate queue and hash table
			BinomialNode * tempNode;
			tempNode = new BinomialNode(line, nullptr, nullptr, nullptr);
			coolBin.binInsert(tempNode);
			counter++;
			coolBin.hashInsert(line, tempNode);
		}
		cout << "Total number of insertions into the binomial queue: " << counter <<endl;
		textFile.close();
	}
	else{
		cout << "File not found." <<endl;					
	}

	for(int i = 0; i < 10; ++i){							//deleting 10 times, find the min in Queue then
		coolBin.minBin();                                   //then delete it
		coolBin.binDeleteMin();
	}

	cout << "Please enter a string to search for: ";		//finding in hash table through user input
	cin >> line;
	coolBin.find(line);	
	
	for(int i = 0; i < 5; ++i){
		cout << "Enter a string to remove: ";					//removing 5 times by user input
		cin >> line;
		coolBin.remove(line);
		coolBin.find(line);
	}
	return 0;
}
void runFindTask(BinQueuePlusPlus &ourQueue){
    
  
    cout<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<"**                  Running Find Task                       **"<<endl;
    cout<<"**************************************************************"<<endl;
    cout<<endl;
    
    string answer;
    do{
        string searchKey;
        //prompt user for key
        cout<<"Please enter a key to find: ";
        cin>>searchKey;
        cout<<"Searching for:  " << searchKey <<endl;
        
        //check if key is in queue
        if(ourQueue.contains(searchKey)){
            cout<< "The find function was successful!"<<endl;
        }else{
            cout<< "The word entered does not exist the database!"<<endl;
        }
        
        
        
        
        cout<<"To search again enter 'y' else hit any key: ";
        cin>>answer;
        cout<<endl;
        
    }while(answer[0] == 'y' || answer[0] == 'Y');
    
    cout<<"Find Task has ended..." <<endl;
        
}