1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
timofeeve [1]
3 years ago
15

Write an abstract data type for a queue in Java whose elements are generic elements of type T that have an associated integer pr

iority. This queue must have the following methods: enqueue, which takes an object of generic type T and an integer (priority) as parameters; dequeue, which returns the generic element from the queue that has the highest priority (and removes that element); and empty that tells if the queue is empty or not. The queue is not to be maintained in priority order of its elements, so the dequeue operation must always search the whole queue. Also, if there are multiple elements with the same priority, the oldest one should be dequeued first.
Computers and Technology
2 answers:
Nimfa-mama [501]3 years ago
7 0

Answer:

See explaination

Explanation:

#include<iostream>

const int MAX=20;

class dque

{

private:

int arr[MAX];

int front,rear;

public:

dque();

void addqatbeg(char item);

void addqatend(char item);

int delqatbeg();

int delqatend();

void display();

int count();

};

dque::dque()

{

front=rear=-1;

for(int i=0;i<MAX;i++)

arr[i]=0;

}

void dque::addqatbeg(int item)

{

if(front==0&&rear==MAX-1){cout<<"\nDeque is full"<<endl;return;}

if(front==-1){front=rear=0;arr[front]=item;return;}

if(rear!=MAX-1)

{int c=count();int k=rear+1;

for(int i=1;i<=c;i++){arr[k]==arr[k-1];k--;}

arr[k]=item;front=k;rear++;

}

else{front--;arr[front]=item;}

}

void dque::addqatend(int item)

{

if(front==0&&rear==MAX-1){cout<<"\nDeque is full"<<endl;return;}

if(front==-1){front=rear=0;arr[rear]=item;return;}

if(rear==MAX-1){

int k=front-1;

for(int i=front-1;i<rear;i++){k=i;

if(k==MAX-1)arr[k]=0;

else arr[k]=arr[i+1];

}rear++;

arr[rear]=item;

}

int dque::delqatbeg()

{

if(front==-1){cout<<"\nDeque is empty"<<endl;return0;}

int item=arr[front];

arr[front]=0;

if(front==rear)front=rear=-1;

else

front++;

return item;

}

int dque::delqatend()

{

if(front==-1){cout<<"\nDeque is empty"<<endl;return 0;}

int item=arr[rear];

arr[rear]=0;

rear--;

if(rear==-1)front=-1;return item;

}

void dque::display()

{

cout<<endl<<"front->";

for(int i=0;i<MAX;i++)cout<<""<<arr[i];cout<<"<-rear";

}

int dque::count()

{

int c=0;

for (int i=0;i<MAX;i++){if(arr[i]!=0)c++;}

return c;}

}

Firdavs [7]3 years ago
6 0

Answer:

Check the explanation

Explanation:

Abstract Data type (ADT) can be refereed to as a class for objects whose behavior is influenced inline with a set of value and a set of operations.

#include<iostream>

const int MAX=20;

class dque

{

private:

  int arr[MAX];

  int front,rear;

public:

  dque();

  void addqatbeg(char item);

  void addqatend(char item);

  int delqatbeg();

  int delqatend();

  void display();

  int count();

};

dque::dque()

{

front=rear=-1;

for(int i=0;i<MAX;i++)

arr[i]=0;

}

void dque::addqatbeg(int item)

{

if(front==0&&rear==MAX-1){cout<<"\nDeque is full"<<endl;return;}

if(front==-1){front=rear=0;arr[front]=item;return;}

if(rear!=MAX-1)

{int c=count();int k=rear+1;

for(int i=1;i<=c;i++){arr[k]==arr[k-1];k--;}

arr[k]=item;front=k;rear++;

}

else{front--;arr[front]=item;}

}

void dque::addqatend(int item)

{

if(front==0&&rear==MAX-1){cout<<"\nDeque is full"<<endl;return;}

if(front==-1){front=rear=0;arr[rear]=item;return;}

if(rear==MAX-1){

int k=front-1;

for(int i=front-1;i<rear;i++){k=i;

if(k==MAX-1)arr[k]=0;

else arr[k]=arr[i+1];

}rear++;

arr[rear]=item;

}

int dque::delqatbeg()

{

if(front==-1){cout<<"\nDeque is empty"<<endl;return0;}

int item=arr[front];

arr[front]=0;

if(front==rear)front=rear=-1;

else

front++;

return item;

}

int dque::delqatend()

{

if(front==-1){cout<<"\nDeque is empty"<<endl;return 0;}

int item=arr[rear];

arr[rear]=0;

rear--;

if(rear==-1)front=-1;return item;

}

void dque::display()

{

cout<<endl<<"front->";

for(int i=0;i<MAX;i++)cout<<""<<arr[i];cout<<"<-rear";

}

int dque::count()

{

int c=0;

for (int i=0;i<MAX;i++){if(arr[i]!=0)c++;}

return c;}

}

You might be interested in
Which organization safeguards americans from health, safety, and security hazards and threats?
Mrrafil [7]

OSHA (Occupational Safety and Health Administration)

4 0
3 years ago
Read 2 more answers
____ involves taking data from your database and putting it into an electronic file in a format that another external applicatio
steposvetlana [31]

Answer:

The answer is "Option c".

Explanation:

In the database dumping a folder for configuration, which information in the file is called a document spill.  In Plesk, exporting a database dump is a file that can be used for storage or delivery, and then preserves a source database is known as Exporting, and other choices are not correct, that are described as follows:

  • Importing, It is a dump in a database, that includes retrieving data from the data in a database location, that's why it's wrong.
  • Enhancing, It automatically improves data, that's why it's wrong.
  • Extracting, It is used in data analyzing and trapped to obtain necessary data from sources, that's why it is wrong.
3 0
3 years ago
Are psn cd keys region free? If not where can I get one in my region?
Andrews [41]
This isn't school related but I'm still gonna help you so you should check the location to see if it's set to be in China if it isn't change it to China if that doesn't work I would just recommend calling customer service if you can.
3 0
3 years ago
Read 2 more answers
Sue is installing a printer. What program will she need to get the printer to work with her computer? Specify some functionaliti
umka21 [38]

Answer:

Utility software tool​

Explanation:

After connecting the printer and turning it on, you'll need to install the printers software and drivers. Every printer should come with the software used to install a printer in Windows or your operating system.

8 0
2 years ago
What controls a computer's basic operations?
S_A_V [24]
 Basic Computer Operations. Input: Information and programs are entered into the computer through Input devices such as the keyboard, disks, or through other computers via network connections or modems connected to the Internet. The input device also retrieves information off disks.
3 0
3 years ago
Other questions:
  • Artists who draw images on a computer often use a stylus in conjunction with special _________ tablets, which offer extra-sensit
    15·1 answer
  • What happens when the computer is thrashing? quizzlet?
    12·1 answer
  • HTTP is made to facilitate which kind of communication?
    11·1 answer
  • What is a directory server?
    5·1 answer
  • In a Comparative Government course, the first unit focuses on the US Congress and the
    8·1 answer
  • As a computer science student, which career you will select and what do you predict about the future of that specific IT-Career.
    8·1 answer
  • If the predetermined overhead allocation rate is 245% of direct labor cost, and the Baking Department's direct labor cost for th
    13·1 answer
  • Anyone know how to delete it in my laptop
    10·1 answer
  • Dominic's teacher asked him to create a chart or graph to compare the different grade levels in the school's FBLA club. Which ch
    5·2 answers
  • Writing a function that implements a loop to collect a set amount of data. The function should use the serial object, the record
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!