Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BinomialQueue.h"
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <string>
- #include <queue>
- #include <stack>
- #include <unordered_map>
- using namespace std;
- //class to test insert and delete
- //holds an instance of Binomial Queue
- class TestInsertAndDelete
- {
- public:
- TestInsertAndDelete() {};
- ~TestInsertAndDelete() {};
- //function to load each item in the file into the queue and hash table
- void load(const string &queue_filename)
- {
- int input_number_;
- ifstream infile;
- //counter to keep track of elements that were inserted
- int number_of_elements_ = 0;
- //opens input file
- infile.open(queue_filename);
- //checks if input file was opened or not
- if(infile.fail())
- {
- cout<<"Queue file could not be found."<<endl;
- return;
- }
- //reads each number from the input file and adds them into the queue and table
- while(infile >> input_number_)
- {
- //inserts the number
- object.insert(input_number_);
- //increases counter by 1
- number_of_elements_++;
- }
- //close queue file
- infile.close();
- cout<<"Success inserting " << number_of_elements_ << " into the queue. The minimum element is "<< object.findMin() << endl;
- }
- //function to read numbers from a file and delete it from the table and queue
- void deleteNumber(const string &check_filename)
- {
- int input_number_;
- ifstream infile;
- //opens deletion file
- infile.open(check_filename);
- //checks if deletion file was opened or not
- if(infile.fail())
- {
- cout<<"Check file could not be found."<<endl;
- return;
- }
- //reads each number from the deletion file and deletes them from the queue and table
- while(infile >> input_number_)
- {
- if(object.contains(input_number_) == true){
- //checks if the queue is empty if it is, display the number deleted and that the queue is empty
- if(object.isEmpty() == true)
- {
- cout<<input_number_<<" Deletion successful - New minimum is nothing"<<endl;
- }
- //if not display the number deleted and the new minimum after the deletion
- else
- {
- cout<<input_number_<<" Deletion successful - New minimum is "<<object.findMin()<<endl;
- }
- }
- }
- }
- private:
- //instance of the binomial queue class
- BinomialQueue<int> object;
- };
- int
- main(int argc, char **argv) {
- if (argc != 3) {
- cout << "Usage: " << argv[0] << " <createqueuefile> <checksearchfile/checkdeletefile> " << endl;
- return 0;
- }
- const string program_type(argv[0]);
- const string create_queue_filename(argv[1]);
- const string check_filename(argv[2]);
- TestInsertAndDelete testing_insert_and_delete;
- testing_insert_and_delete.load(create_queue_filename);
- testing_insert_and_delete.deleteNumber(check_filename);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement