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
To edit the text in a smartart graphic, what must be done first ?
ICE Princess25 [194]
C Hope this helps :D
8 0
2 years ago
Read 2 more answers
The class at the top of exception class hierarchy is ..........................
Lynna [10]

Answer:

<u>B) Throwable</u>

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

There are a wide range of classes on the exception class hierarchy. All the way on the top is the Objects Class but since that is not an available answer we will move on to the next one. The next one is the <u>Throwable</u> class. therefore that is the answer.

**Exception is after Throwable , and Arithmetic Exception is at the bottom.... everything is a class so that is not a part of the hierarchy **

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

6 0
3 years ago
Why is wider channel bandwidth good?
Nookie1986 [14]

Answer:

The wider channel bandwidth is efficient and good as it help in increasing the speed of the transmission. Due to the wider channel of the bandwidth it also lead to consuming less energy of the battery and make cost effective.

Due to the wider bandwidth, the number of clients can easily share and transfer the data in the channel and also make the transmission complete.

If the channel of the bandwidth is double then, the single transmission can easily carry more data. Hence, it also lead to double the speed of the transmission.

7 0
3 years ago
What led to fall of axum?
stiks02 [169]
The main factors that led to the fall of the Aksum in the seventh century were climate change and the obstruction of international trade routes around the Red Sea brought on by the growing supremacy of the Muslims in Ethiopia.<span> Other contributing factors included a reduced crop yield due to excess cultivation of land, Persian interference and the rise of Christianity in the region.</span>
3 0
2 years ago
Read 2 more answers
Which of the follow represents a form of disruptive technology? Tend to open new markets and destroy old ones A new way of doing
RSB [31]

Answer: All of the above are included

Explanation: Disruptive technology is the created for the manipulation of the business operations and related components significantly.It works by changing the habits of the business system by its more superior standards and ways.

The opening of new market to eliminate the older market, invoking in the marketplace for cheap range of goods and making a new strategy that does not fulfill the demand of the customer are disruptive strategy as they change the regular way of business operation through their techniques.

4 0
3 years ago
Other questions:
  • What type of rain happens when cold air meets warm air
    14·1 answer
  • Whos ready for sao ordinal scale this march!!!( ಥـْـِـِـِـْಥ)
    7·1 answer
  • A hub or ____ is a central point that connects several devices in a network together.
    11·1 answer
  • Which of the following best describes a toolbar?
    7·1 answer
  • What are the modes of operation of WLANs?
    5·1 answer
  • You’re browsing the internet and realize your browser is not responding. Which of the following will allow you to immediately ex
    11·1 answer
  • Create a Divisible application that displays a random integer between 1 and 100 and displays appropriate messages stating whethe
    5·1 answer
  • What helps you evaluate websites for reliable information?
    15·2 answers
  • A serial schedule:
    8·1 answer
  • Select the best answer from the drop-down menu.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!