Yurttas/PL/IL/Ada-95/F/03/02/01/queue 01 p.adb

 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_01_p.adb
15
16
17package body Queue_01_P is
18
19  Queue_Size : constant Integer := 10;
20  subtype Queue_Index is Integer range 0..Queue_Size-1;
21
22  Queue_Head   : Queue_Index;
23  Queue_Length : Integer range 0..Queue_Size;
24  Queue_Body   : array(Queue_Index) of Float;
25
26  function Full return Boolean is
27  begin
28    return Queue_Length = Queue_Size;
29  end Full;
30
31  function Empty return Boolean is
32  begin
33    return Queue_Length = 0;
34  end Empty;
35
36  procedure Enqueue(E : in Float) is
37  begin 
38    if Full then
39      raise Overflow;
40    end if;
41
42    Queue_Body((Queue_Head+Queue_Length) mod Queue_Size) := E;
43    Queue_Length := Queue_Length + 1;
44  end Enqueue;
45
46  function Dequeue return Float is
47    E : Float := Queue_Body(Queue_Head);
48  begin 
49    if Empty then
50      raise Underflow;
51    end if;
52
53    Queue_Head := (Queue_Head+1) mod Queue_Size;
54    Queue_Length := Queue_Length - 1;
55
56    return E;
57  end Dequeue;
58
59begin
60
61  Queue_Head   := 0;
62  Queue_Length := 0;
63
64end Queue_01_P;