Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

priority queues

Status
Not open for further replies.

oinkers

Programmer
Jun 14, 2000
23
0
0
US
I have been using queues in perl with the array data structure using push and shift commands. This works great but now i need to implemnt a prioity queue structure. Which means i cant be using an array anymore, i need to have a linked list. I am not sure how to make a link list in perl. Does any1 have any ideas?<br>please help thanks.
 
So, using push and shift you used standard arrays to hold data items...&nbsp;&nbsp;You now want to assign, for want of a better phrase, a priority field to each item in your queue?&nbsp;&nbsp;Would using a hash with the priority as the key value work for you?<br><br>For example:<br><FONT FACE=monospace><br>$Queue{'1'} = &quot;Most important item&quot;;<br>$Queue{'2'} = &quot;A less important item&quot;;<br>$Queue{'100'} = &quot;Bottom of the heap whatever else happens&quot;;<br></font><br><br>It should be fairly easy to create some function to insert/delete items from the queue, possibly re-numbering (re-keying) displaced queue items.&nbsp;&nbsp;(Careful though, I've got a reputation for saying &quot;It should be fairly easy...&quot; just before a few days of head scratching... ;^) <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
That should work just as long as you make sure no two items can have the same priority :eek:) <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top