• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I sort this queue

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I really would appreciate some help with getting this method working and finding out where I went wrong. Basically I have an event called insertevent. This method will take an event and place it in the right order in the queue. So the queue is already sorted I just have to find the insertion point for this event.
What I do is I created a temporary queue, a deque an element from the original queue and compare that element with the inserted element if the inserted element is less then the dequeud element I put it on the temporary queue. if not I put the inserted element on the temporary queue. Then when all the elements are in the temporary queue I used a while loop to restore the old queue by placeing each element back in. So in theory it works but not when I I actually runt it, and it seems that the nothing is happening in the first while loop. Where did I go wrong? My proffessor has said that this is similar to a priority queue but instead we are supposed to use O(n) enqueuing and dequing. Here is my code:pastebin
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Your description is difficult to read, I am afraid; I think there are some spelling errors in it. Please post the code here, since people don't like looking elsewhere.
 
bacon. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic