-- File Queueg.adb -- This is a generic queue package, built on top of a generic list -- package (listg) that handles most of the pointer manipulation. -- It will later be used in a graph traversal program. package body Queueg is procedure Copy (From: in Queue; To: in out Queue) is index, trail: List; begin Copy (From.Front, To.Front); -- copy list pointed to by Front if Empty (To.Front) then Clear (To.Rear); else index := To.Front; while not Empty (Rest (index)) loop index := Rest (index); end loop; To.Rear := index; end if; end Copy; procedure Clear (AQueue: in out Queue) is begin Clear (AQueue.Front); Clear (AQueue.Rear); end Clear; procedure Add (Item: in Element; ToQueue: in out Queue) is temp: List; begin Cons (Item, temp); Append (temp, ToQueue.Front); if Empty (ToQueue.Rear) then ToQueue.Rear := ToQueue.Front; else ToQueue.Rear := Rest (ToQueue.Rear); end if; exception when Overflow => raise Overflow; end Add; procedure Pop (AQueue: in out Queue) is begin if Empty (AQueue) then raise Underflow; else AQueue.Front := Rest (AQueue.Front); if Empty (AQueue.Front) then Clear (AQueue.Rear); end if; end if; end Pop; function Equal (Left: in Queue; Right: in Queue) return Boolean is begin return Equal (Left.Front, Right.Front); end Equal; function Empty (AQueue: in Queue) return Boolean is begin return Empty (AQueue.Front); end Empty; function First (OfQueue: in Queue) return Element is -- datum of front of queue begin if Empty (OfQueue.Front) then raise Underflow; else return First (OfQueue.Front); end if; end First; end Queueg;