I am having trouble with a program where I need to write a priority queue and a max heap implementation. We can use a vector to dynamically add elements or use an array. I chose to use a vector since it will be easier. Now what the program does is displays a menu and the user has an option to chose 1.) to add job, 2.) print job, and 3.) view job. The fourth option is to exit the program. the first option is what makes the program and is where I am having trouble because it keeps crashing. If the user presses option one, it will display who is requesting the job, Student, TA, or Instructor. This is where the priority comes in. The instructor has the highest priority, TA coming in second, and student being last. When the user chooses to press option 2 and there are 4 people waiting in the priority, the instructor gets to get printed first and when the user presses option 3 to view jobs there would be three people waiting left. Which could be any of three. Next if there are no instructors waiting to be printed then TA gets to go first then if student is the remaining one then he gets to go. The position will be an integer in the queue starting from one and increments everytime someone gets added. When the user decides to print job or view job its suppose to print out Job #: with the name of who is in the queue. So for exmaple, Job#1: Student, Job#2: TA, Job#3: Instructor, Job#4: Instructor........
Also, presumably you want everything to be operating on the same PQTYPE object? You're passing it by value, so copies are being made. Pass by reference.
m_Items.m_elements.push_back(m_size); This seems odd. You're putting the number zero into the vector. Why?
You never change the value m_size. Is that how you're trying to keep track of how many elements you've added? It never changes.
I didn't put anything in the Enqueue function because I didn't mean to show you all of it. I have fixed my problem. It now adds items to the vector. here is what I have changed.
1 2 3 4 5 6 7 8 9 10 11 12
void addJobs(PQTYPE& pq, int jp)
{
char jobChoice;
std::cout << "Who is the job for ( Instructor(i or I), TA(t or T), Student(s or S) :";
std::cin >> jobChoice;
if (jobChoice == 'S' || jobChoice == 's' || jobChoice == 'I' || jobChoice == 'i' || jobChoice == 't' || jobChoice == 'T')
{
pq.Enqueue(JobPerson::jobPosition);
}
}
From my structure I have a static variable and I initialize it to one. The reason I initialized it to one because it needs to start at one and then increment every time I add a new job to the the queue, but it does not increment. When I press the view jobs, it shows the job#1 all the time instead of job#1: then the next line should job#2: job#3: job#4: .......