Solved

How to implement the standard Queue ADT?

Posted on 2008-06-16
8
1,275 Views
Last Modified: 2009-05-23
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
Comment
Question by:secondcup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 53

Expert Comment

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

Author Comment

by:secondcup
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

by:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Assisted Solution

by:Sankozi
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)
    {
      reload(); //"restart" queue
    }
  }
 
  T pop()
  {
    p.getNext();
  }
 
  void reload()
  {
    oldPQ = pQueue;
    pQueue = new PQueue();
    nextPriority = Integer.MAX_VALUE;
 
    while(!oldPQ.empty())
    {
      push(oldPQ.pop());
    }
  }
}

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
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

by:CCSINCOMETRUST
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question