Question

C++ ***Please include makefile*** Requirements: You should name your Prority Queue class as PQ. The queue...

C++

***Please include makefile***

Requirements: You should name your Prority Queue class as PQ. The queue must be able to hold unlimited number of integers. It has two key operations: Push and Pop, which should have the time complexity of O(logn). Files to turn in: You need to turn in four files: makefile, main.C, PQ.C, PQ.h. You should have a main.C that reads in or generates some integers, pushes them into the PQ one by one, and pops and prints them until the PQ is empty. Grading The total points is 12, you will get full credit if you correctly implement it using tree structure, 6 points if you correctly implement it using array. No late turn in is acceptable, any late turn in will be given 0 points. Your code must be compilable on Linux/Unix, any code that cannot be compiled by g++ will automatically get ZERO points.

Homework Answers

Answer #1

pq.c
-------------------------------------
#Define pq.h

class pq
{
   int a[SIZE];
   int front;
   int rear;
public:
   pq();
   ~pq();
   void push(int i);
   int pop();
   int isempty();
   int isfull();
};

pq::pq()
{
front=0;
rear=0;
}
pq::~pq()
{
delete []a;
}
void pq::push(int i)
{
if(isfull())
{
   cout<<"Queue is FULL !!!No insertion allowed further";
   return;
}
a[rear] = i;
rear++;
}
int pq::pop()
{
if(isempty())
{
   cout<<"Queue Empty !!!Value returned will be garbage";
   return (-9999);
}

return(a[front++]);
}
int queue::isempty()
{
if(front == rear)
   return 1;
else
   return 0;
}
int queue::isfull()
{
if(rear == SIZE)
   return 1;
else
   return 0;
}
main.c
------------------------------------------------------------------
# include<iostream.h>
# include<conio.h>
#include<pq.h>

void main()
{
int ch;
pq queue;
while(1)
{
cout <<"\n1.push 2.pop 3.exit\nEnter ur choice";
cin >> ch;
switch(ch)
{
case 1: cout <<"enter the element";
    cin >> ch;
queue.push(ch);
break;
case 2: queue.pop(); break;
case 3: exit(0);
}
}
return (0);

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
The Business Case for Agility “The battle is not always to the strongest, nor the race...
The Business Case for Agility “The battle is not always to the strongest, nor the race to the swiftest, but that’s the way to bet ’em!”  —C. Morgan Cofer In This Chapter This chapter discusses the business case for Agility, presenting six benefits for teams and the enterprise. It also describes a financial model that shows why incremental development works. Takeaways Agility is not just about the team. There are product-management, project-management, and technical issues beyond the team’s control. Lean-Agile provides...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT