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]
4 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]4 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]4 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
Explain: The fetch part of fetch decode execute cycle
MArishka [77]

Answer:

Look at the image

Explanation:

7 0
3 years ago
For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, D
Bad White [126]

The answer & explanation for this question is given in the attachment below.

Download docx
4 0
3 years ago
What is the overall objective of an IT risk assessment? To assist IT management in establishing a budget for countermeasures To
QveST [7]
The overall objective of an IT risk assessment is to assist an organization in identifying risks and impacts.<span> The process includes discovering, correcting and preventing security problems.</span>
The IT risk assessment document identifies threats, estimates risks and determines how to manage them.
4 0
3 years ago
Is co2+4h2--&gt; ch4 + 2h2o a combustion​
Nadya [2.5K]

Answer:

No its not a combustion its a formation.

Explanation:

7 0
3 years ago
Question 5 of 5
Archy [21]

<u>Answer:</u>

<em>Sewage treatment Programs </em>

<u>Explanation:</u>

Sewage treatment programs are the right choice <em>because these are the source to create germs and if we understand how to be clean, most of the disease is avoided. </em>

<em>Drug regulation:</em> It is nothing but the continuous treatment of prolonged disease where pills needs to be taken regularly to protect patients from death or to avoid disease become more severe.

<em>Physical fitness campaign:</em> This concentrate on to how to keep bod fit through exercise and it does not deal with hygiene.

<em>Nutrition Education:</em> It’s a kind of protection mechanism where in-take of food is really concentrated to fight against germs.

5 0
4 years ago
Other questions:
  • Ben works at a top accounting firm in Salt Lake City and his responsibilities include developing individual and departmental goa
    9·1 answer
  • The united states attempted to halt the communist revolution in cuba by​
    7·1 answer
  • write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
    5·1 answer
  • Most licensing agencies offer an orientation meeting for applicants who want to obtain licensing for a child care facility or a
    12·2 answers
  • In the Word 2016 window, where is the Status bar located?
    8·1 answer
  • Sensing that the future of computing was in personal computers and that computers' power would reside not in their size but in t
    5·1 answer
  • Which of the following is a proper use of the application, netstumbler
    9·2 answers
  • Consider a hypothetical hard drive that has 400,000 cylinders, 8 heads, and 128 sectors per track. Demonstrate, in writing, how
    9·1 answer
  • Which type of file can be opened directly into Excel?
    15·1 answer
  • Choose the output result of the below code.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!