1--
2-- Copyright(C) 1998
3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4--
5-- Permission to use, copy, modify, and distribute this
6-- software and its documentation for EDUCATIONAL purposes
7-- and without fee is hereby granted provided that this
8-- copyright notice appears in all copies.
9--
10
11-- date : January 1, 1998.
12-- author : Salih Yurttas.
13
14-- queue_02_p.adb
15
16
17package body Queue_02_P is
18
19 subtype Queue_Index is Integer range 0..Queue_Size-1;
20
21 Queue_Head : Queue_Index;
22 Queue_Length : Integer range 0..Queue_Size;
23 Queue_Body : array(Queue_Index) of Element;
24
25 function Full return Boolean is
26 begin
27 return Queue_Length = Queue_Size;
28 end Full;
29
30 function Empty return Boolean is
31 begin
32 return Queue_Length = 0;
33 end Empty;
34
35 procedure Enqueue(E : in Element) is
36 begin
37 if Full then
38 raise overflow;
39 end if;
40
41 Queue_Body((Queue_Head+Queue_Length) mod Queue_Size) := E;
42 Queue_Length := Queue_Length + 1;
43 end Enqueue;
44
45 function Dequeue return Element is
46 E : Element := Queue_Body(Queue_Head);
47 begin
48 if Empty then
49 raise underflow;
50 end if;
51
52 Queue_Head := (Queue_Head+1) mod Queue_Size;
53 Queue_Length := Queue_Length - 1;
54
55 return E;
56 end Dequeue;
57
58begin
59
60 Queue_Head := 0;
61 Queue_Length := 0;
62
63end Queue_02_P;