• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I sort this queue  RSS feed

 
ama ma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!