#include <iostream>
#include <cassert>
using namespace std;
struct node {
int number;
bool high_priority;
node *link;
};
class linkedPriorityQueue {
private:
node *high_priority_front,
*high_priority_rear,
*queue_front,
*queue_rear;
public:
linkedPriorityQueue();
void addQueue( int number, bool high_priority );
void deleteQueue();
int front();
int back();
bool empty();
bool full();
void print();
int size( bool high_priority);
~linkedPriorityQueue();
};
int main() {
bool t;
int i, j;
linkedPriorityQueue q1;
for( i = 0; i < 9; i++ ) {
t = bool( rand() % 2 );
q1.addQueue( i, t );
cout<<"Customer "<<i<<( t ? " with high-priority " : " " )<<"aded to the queue."<<endl;
}
q1.addQueue( i, true );
cout<<"Customer "<<i<<" with high-priority aded to the queue."<<endl;
cout<<"\nThe number of high-priority customers is "<<q1.size( true )
<<",\nwhile the number of remaining customers is "<<q1.size( false )<<"."<<endl;
cout<<"\nCustomer number "<<q1.front()<<" is at the front of the queue,"
<<"\nwhile customer number "<<q1.back()<<" is at the end of the queue."<<endl;
cout<<endl;
q1.print();
j = q1.size( true ) + q1.size( false ) / 2;
for( i = 0; i < j; i++ )
q1.deleteQueue();
cout<<"\nAfter a few removals, the number of high-priority customers is "<<q1.size( true )
<<",\nwhile the number of remaining customers is "<<q1.size( false )<<"."<<endl;
cout<<"\nCustomer number "<<q1.front()<<" is at the front of the queue,"
<<"\nwhile customer number "<<q1.back()<<" is at the end of the queue."<<endl;
cout<<endl;
q1.print();
return 0;
}
esraa waqfi 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.