program SeqList;

const
  max = 10;                             {Maximum size of List}

type
  itemtype = integer;                   {Contents of List}

  list = record                         {List Structure}
    items: array [1..max] of itemtype;  {The items}
    next: integer;                      {Position of next empty space}
  end;


{*****************************************
Procedure to Initialise a List
Pre: List not initialised
Post:List initialised with first position
     ready to accept the first item.
******************************************}
procedure init(var l:list);
  begin
    l.next:=1;                          {First position available}
  end;


{*****************************************
Function to return True/False if list is full
Pre: List initialised
Post:List unchanged
******************************************}
function isFull(l:list): boolean;
begin
isFull:=l.next=max+1;   {Next available position is out of array}
end;

{*****************************************
Function to return True/False if list is empty
Pre: List initialised
Post:List unchanged
******************************************}
function isEmpty(l:list): boolean;
begin
isEmpty:=l.next=1;      {Next available position is still at 1}
end;


{*****************************************
Function to return number of items in List
Pre: List initialised
Post:List unchanged
******************************************}
function itemNo(l:list): integer;
begin
itemNo:=l.next-1;       {Number of item is one less the next position}
end;


{*****************************************
Procedure to Insert an item in the List
Pre: List initialised
Post:List has item inserted
******************************************}
procedure insert(var l:list;i:itemtype);
  begin
    if (isFull(l))                              {if list is full}
     then writeln('Sorry - List is Full')       {then }
     else                                       {else }
       begin
         l.items[l.next]:=i;    {place item in next available position}
         l.next:=l.next+1;      {move to next available position}
       end;
  end;


{*****************************************
Procedure to DISPLAY all items in the List
Pre: List initialised
Post:List unchanged
******************************************}
procedure display(l:list);
var
i:integer;

  begin
    for i:= 1 to l.next-1 do
        writeln(l.items[i]);

  end;


{*****************************************
Procedure to delete a particular item in the List
Pre: List initialised and item is in the list
Post:List has item removed
******************************************}
procedure delete(var l:list;i:itemtype);
var
counter:integer;
found:integer;

  begin
    for counter:= 1 to l.next-1 do
        if (l.items[counter]) = i
         then
          begin
           for found:=counter to l.next-1 do
               l.items[found]:=l.items[found+1];
           l.next:=l.next-1;
           counter:=l.next-1;
          end;

  end;




{*****************************************
               MAIN PROGRAM
******************************************}
Var
  TestList:list;
  numru:integer;

BEGIN
  init(TestList);


  insert(TestList,6);

  insert(TestList,24);

  insert(TestList,28);

  insert(TestList,32);

  insert(TestList,55);

  insert(TestList,78);
  display(TestList);
  delete(TestList,24);
  display(TestList);
  writeln('Number of items in list: ',itemNo(TestList));
END.


