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 7516199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:03:33+00:00 2026-05-30T01:03:33+00:00

If I want to print out values in a PriorityQueue , how can I

  • 0

If I want to print out values in a PriorityQueue, how can I do it? I extended PriortiyQueue, and got access to the underlying list queue. However when I do a for loop, I get the order in which items are added

# the ADT PriorityQueue
class ReadyQueue(PriorityQueue):
    ...

    def listAll(self):
        print("PID \t Name \t Status \t Priority")
        print("=" * 42)
        for _, _, pcb in self.queue:
            print(pcb)

# ADT 
class PCB:
    ...
    def __lt__(self, other):
        selfPriority = (self.priority, self.creationTime)
        otherPriority = (other.priority, other.creationTime)
        return selfPriority < otherPriority

# in the main function
q = ReadyQueue()
q.enqueue(PCB("p1", 0, None, q))
q.enqueue(PCB("p8", 6, None, q))
q.enqueue(PCB("p2", 1, None, q))
q.enqueue(PCB("p0", 1, None, q))
q.enqueue(PCB("p6", 1, None, q))
q.enqueue(PCB("p4", 1, None, q))
q.enqueue(PCB("p3", 2, None, q))

q.listAll()

The output:


 PID     Name    Status      Priority
 ==========================================
 0   p1      ready_s     0
 3   p0      ready_s     1
 2   p2      ready_s     1
 1   p8      ready_s     6
 4   p6      ready_s     1
 5   p4      ready_s     1
 6   p3      ready_s     2

Notice priority is not right. Though they dont appear in creation order either … did I miss something?

  • 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-05-30T01:03:34+00:00Added an answer on May 30, 2026 at 1:03 am

    PriorityQueue use heapq to push and pop elements, http://docs.python.org/library/heapq.html

    so, the queue is a heap, not a sorted list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to print out all of the values in my array, however the
I am iterating over a list and I want to print out the index
Basically, I want to print out a string of values in a single line,
I want to sum acidic as the for loop runs and then print out
Attempting to print out a list of values from 2 different variables that are
Am doing development on google app engine and i want to print out values
I have a List<object> . I want to loop over the list and print
Is there anyway I can print out the Keys with the values that had
I want to print out some debug messages in my erb template when it
I want to print out a derived class using the operator<< . When I

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.