[comp.lang.pascal] Priority queue

TAIBI91%SNYNEWVM.BITNET@uga.cc.uga.edu (S. Taibi) (03/15/91)

I don't have the code handy, but here is a suggestion:

Make the node of the linked list like this:

NODE = RECORD
  PRIORITY : INTEGER;
  ELEMENT  : <element type> ; { whatever data is being listed }
  NEXT     : @NODE;
  END;

Insert to the list by simply appending to the end of the list, and
worry about checking priority only when removing a node from the list.
This is probably the simplest way to implement a prority queue,
but it is not the fastest.

I hope this helps.

S. Taibi

kushmer@bnlux1.bnl.gov (christopher kushmerick) (03/21/91)

In article <26282@adm.brl.mil> TAIBI91%SNYNEWVM.BITNET@uga.cc.uga.edu (S. Taibi) writes:
>I don't have the code handy, but here is a suggestion:
>
>Make the node of the linked list like this:
>NODE = RECORD
>  PRIORITY : INTEGER;
...
>
>Insert to the list by simply appending to the end of the list, and
>worry about checking priority only when removing a node from the list.
>This is probably the simplest way to implement a prority queue,


But what heppens when an event of high priority is queued while an event of
lower priority is hapening? How does this scheme allow for preemption?

Dummyline
Dummyline
Dummyline
Dummyline
Dummyline
Dummyline
Dummyline
Dummyline
-- 
Chris Kushmerick                                 kciremhsuK sirhC
kushmer@bnlux1.bnl.gov    <===Try this one first
kushmerick@pofvax.sunysb.edu