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 method adds 10 to the right end of the array?<br> myArray.<br> insert<br> (10)
vladimir1956 [14]

JavaScript has a set of mutator functions that allow you to modify the contents of an array without referencing the individual elements.To add to to myArray we us the push() method

<h3>Adding Elements to an Array</h3>

To add to to myArray we us the push() method

(10)

myArray.push(10)

There are two mutator functions for adding elements to an array: push() and unshift(). The push() function adds an element to the end of an array:

var nums = [1,2,3,4,5]; print(nums); // 1,2,3,4,5 nums.push(6);

print(nums); // 1,2,3,4,5,6

var nums = [1,2,3,4,5]; print(nums); // 1,2,3,4,5 nums[nums.length] = 6; print(nums); // 1,2,3,4,5,6

Learn more about arrays here:

brainly.com/question/24275089

6 0
2 years ago
In the LC-3, how many memory words are used to store the string "rainbow"?
oksian1 [2.3K]
The number of memory words used to store the string "rainbow" is 8.
5 0
3 years ago
State the major different between fours types of computers
Igoryamba

Answer:

1. Supercomputers

Supercomputers are very expensive and very fast. They are the most powerful computers we have in the world.

Supercomputers are optimized to execute only a small number of programs. This makes it possible for them to execute these few programs at a very high speed. Due to their inhibiting cost, they are used in high-end places like in scientific research centers. The supercomputer consists of thousands of processors, allowing it to clock in at very high speeds measured by petaflops.

These computer types are also very large in size due to the numerous parts and components involved in their design.

A good example of a supercomputer is Tianhe-2, which is located in the National Supercomputer Center in Guangzhou, China. It features 3.12 million cores, allowing it to run at speeds of 33.86 petaflops.

2. Mainframe Computers

These are large and expensive computers that are capable of supporting thousands of users simultaneously. They are mostly used by governments and large organizations for bulk data processing, critical applications, and transaction processing. They are ranked below supercomputers.

3. Minicomputers

Minicomputers are mid-sized computers. In terms of size and power, they are ranked below mainframes. A minicomputer is a multiprocessing system capable of supporting from 4 to about 200 users simultaneously.

The use of the term minicomputer has diminished since the introduction of microprocessors. These machines are now more commonly called midrange computers.

4. Microcomputers

A microcomputer, also known as a personal computer, is designed to be used by one user at a time. The term microcomputer relates to the microprocessor that is used for the purpose of processing data and instruction codes. These are the most common computer types since they are not very expensive

8 0
2 years ago
Provide all resonance structures of the sigma complex when aniline reacts with an electrophile to yield the para-substituted pro
Nadya [2.5K]

Answer:

See attached picture.

Explanation:

See attached picture for detailed explanation.

3 0
3 years ago
Flinstonia has a real GDP of $100,000, and Bedrockton has a real GDP of $100,000,000. Which country has the higher standard of l
Lunna [17]

Bedrockton because the higher the GDP the higher the living standard.

3 0
3 years ago
Other questions:
  • In this type of network, data is certain to reach its destination.
    7·1 answer
  • Each object that is created from a class is called a(n) ____________ of the class.
    5·2 answers
  • Write a method called makeLine. The method receives an int parameter that is guaranteed not to be negative and a character. The
    11·1 answer
  • An IT firm came across a startup company that offers a new system of computer storage. It is currently in the experimental phase
    11·1 answer
  • Flash drives, CDs, external disks are all examples of storage (memory) devices.'True or false?
    9·1 answer
  • AP CSP - Write a program that takes 10 random numbers from 1 to 12 inclusively and averages them together.
    8·1 answer
  • What are the steps for adding an action button to a slide? Choose the correct answers from the drop-down menus. 1. First, go to
    5·2 answers
  • The illustration shows different types of text language.
    5·2 answers
  • Task queues, which allow for asynchronous performance, are an important part of modern processing architectures. Information abo
    13·1 answer
  • Describe the specific job you would want to have if you were going to pursue a career in digital music or video.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!