Solved

# How to implement the standard Queue ADT?

Posted on 2008-06-16
1,183 Views
Hello.
I have to show how to implement the standard Queue ADT using only a Priority Queue and one additional integer instance variable. Can anyone provide a text description of the process?
0
Question by:secondcup

LVL 53

Expert Comment

ID: 21795843
Is this an assignment ? How far did you get ? What are you unsure about ?
0

Author Comment

ID: 21796786
I have no idea how to implement the Queue ADT using only a Priority Queue and one additional integer instance variable.  I just know we can implement it by using List...but I do not get what it means by one additional integer..
0

LVL 53

Accepted Solution

Infinity08 earned 168 total points
ID: 21796980
A queue is a special case of a priority queue, where the priority is basically the time of insertion.
0

LVL 3

Assisted Solution

Sankozi earned 166 total points
ID: 21797194
I think this is good solution. You just need this additional integer to determine priority of next element that will be pushed.
``````

class Queue

{

PQueue pQueue = new PQueue();

int nextPriority = Integer.MAX_VALUE;

void push(T t)

{

pQueue.insertWithPriority(t, nextPriority --);

if(nextPriority == Integer.MIN_VALUE)

{

}

}

T pop()

{

p.getNext();

}

{

oldPQ = pQueue;

pQueue = new PQueue();

nextPriority = Integer.MAX_VALUE;

while(!oldPQ.empty())

{

push(oldPQ.pop());

}

}

}
``````
0

LVL 53

Expert Comment

ID: 21797260
Sankozi, be careful with posting full code solutions to what might be an assignment - that's not permitted on this site.
0

LVL 1

Assisted Solution

CCSINCOMETRUST earned 166 total points
ID: 21917134
You may want to consider implementing a circular queue depending on what it will be used for and if you don't know how much it will hold ahead of time.

Hint: Google "Java Circular Queue" or "C++ Circular Queue" - you should have no problem finding code that you can use.
0

## Featured Post

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…