Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:33:30+00:00 2026-06-03T05:33:30+00:00

I have a project with priority queues and reqular queues. I need to organize

  • 0

I have a project with priority queues and reqular queues.
I need to organize products by IDs from min to max using priority queues.

And then using reqular queues I need to put them into 3 categories:
(over-stock, under-stock, within limits); so the output should look like this:

UnderStock

14887 $10 14

15678 $1 298

OverStock

12565 $4 539

18967 $12 401

StockWithinLimits

19847 $2 220

I wrote this code, but something is off that I am not sure and my out put looks like:

OverStock

12565 $4 539

UnderStock

14887 $10 14

UnderStock

15678 $1 298

OverStock

18967 $12 401

StockWithInLimits

19847 $2 220

int main() 
{ 
    ifstream inFile; // file containing operations 
    ofstream outFile; // file containing output 
    string inFileName = "product.txt"; 
    string outFileName = "result.txt"; 
    inFile.open (inFileName.c_str()); 
    outFile.open (outFileName.c_str()); 
    ItemType item;//declare a temp item that trows into pQue 
    PQType<ItemType> pqueue(50);//priority queue that sorts items by ID 
    QueueADT <ItemType> que; 
    QueueADT <ItemType> lowQ;
    QueueADT <ItemType> highQ;
    QueueADT <ItemType> withinQ;

    while ( item.readProduct (inFile) ) 
    { 
        pqueue.Enqueue(item); 

    } 

    while (!pqueue.IsEmpty()) 
    { 
        pqueue.Dequeue (item); 
        int tempcurinvent = item.getcurrentInventory (); 
        int tempmax = item.getMax (); 
        int tempmin =item.getMin (); 

    if ((tempcurinvent < tempmin) && (tempcurinvent < tempmax))//UnderStock 
        {
            lowQ.Enqueue (item);
        }

if ((tempcurinvent < tempmax) && ( tempcurinvent  > tempmin)) //WithINLimits
        { 
            withinQ.Enqueue (item);
        } 
else if ((tempcurinvent > tempmin) && (tempcurinvent > tempmax))//OverStock 
        { 
            highQ.Enqueue (item);
        }
        outFile << "UnderStock" << endl;
        item.printProduct (outFile);
        lowQ.Dequeue (item);

        outFile << "WithINLimits:" << endl;
        item.printProduct (outFile); 
        withinQ.Dequeue (item);

        outFile << "OverStock" << endl; 
        item.printProduct (outFile); 
        highQ.Dequeue (item);

    }

    inFile.close (); 
    outFile.close (); 



  return 0; 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:33:32+00:00Added an answer on June 3, 2026 at 5:33 am

    An odd use for a priority queue but I suppose that is the requirements.

    (1) You put everything in the pqueue. That’s good. You should then empty the pqueue and using the under/over/within logic put the items into one of the three regular queues. THEN read each of queues (printing the header “over”, “under”, “within” first) and print them out.

    (2)

    QueueADT <int> que;
    
    que.Enqueue (n);
    

    looks wrong. Why are you queing an int and not the item? Why do you have one queue and not three? This applies to que.Deque(n) statements as well.

    (3) You don’t really need compound IF statements. Presumably if something is below the minimum it is also below the maximum.

    So something like

     if belowMin
         put in lowQ
         readagain
    
     if aboveMax
         put in highQ
         readagain
    
     put in withinQ
    

    Also be careful to make sure you want item < max rather than item <= max, depending on what the specs say.

    EDIT

    These neeed to be outside the current while loop:

    outFile << "UnderStock" << endl;
    while (!lowQ.IsEmpty())
    {
        lowQ.Dequeue (item);
        item.printProduct (outFile);
    }
    
    outFile << "WithINLimits:" << endl;
    while (!withinQ.IsEmpty())
    {
        withinQ.Dequeue (item);
        item.printProduct (outFile);
    }
    
    outFile << "Overstock:" << endl;
    while (!highQ.IsEmpty())
    {
        highQ.Dequeue (item);
        item.printProduct (outFile);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net
I am very desperate now... I have project in Visual C++ 2010 using Qt
I have a project where I need to show a TextField with a monetary
We're using TFS with MSF for Agile 4.2 on a project, and I have
I have been using OCUnit for unit testing in a project. I've managed to
I have been working on a project which is about data copy from one
I have a project using log4j. Now I have to introduce a library using
I have project that uses Hibernate: hibernate-core-3.6.7.Final.jar In its POM I found: <dependency> <groupId>org.hibernate.javax.persistence</groupId>
I have project in Dropbox and two running laptops: one with Ubuntu and one
I have project written in Zend Framework and it works fine most of environments.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.