tpu/u_colaai.pas

{ ppc386 -va -vh *.pas }
{ COMIENZO DE DESCRIPCION

  Colas de enteros por arreglos.
  keywords: cola, arreglos

FIN DE DESCRIPCION }
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
{ $Id: u_colaai.pas,v 1.1 2002/04/25 15:57:09 mstorti Exp mstorti $}

unit u_colaai;

interface

const
  long_max =  100;

type
  tipo_elemento = integer;

  colaai = object
  private
    elementos : array [1..long_max] of tipo_elemento;
    ant, post: integer;
    procedure ERROR (s: string);
    function  SUMA_UNO (i: integer): integer;
  public
    procedure ANULA;
    procedure PONE (x: tipo_elemento);
    procedure QUITA;
    function  VACIA : boolean;
    function  FRENTE : tipo_elemento;
    procedure IMPRIME (s : string) ;
  end;			    

implementation

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure colaai.ERROR (s: string);
begin
  write ('error: ');
  writeln (s);
  halt;
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
function  colaai.SUMA_UNO (i: integer): integer;
begin
  suma_uno := (i mod long_max) + 1;
end; {suma_uno}

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure colaai.ANULA;
begin
  ant := 1;
  post := long_max;
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure colaai.PONE (x: tipo_elemento);
begin
  if (SUMA_UNO (SUMA_UNO (post) ) = ant) then
     ERROR ('la cola esta llena')
  else begin
     post := SUMA_UNO (post) ;
     elementos [post] := x ;
  end ; {if}
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure colaai.QUITA;
begin
  if ( VACIA ) then
    ERROR ('la cola esta vacia')
  else begin
    ant := SUMA_UNO (ant)
  end ; {if}
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
function colaai.VACIA : boolean;
begin
  VACIA := (SUMA_UNO (post) = ant);
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
function colaai.FRENTE : tipo_elemento;
begin
  if ( VACIA ) then
    ERROR (' la cola esta vacia')
  else begin
    FRENTE := elementos [ant] ;
  end ; {if}
end;

{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure colaai.IMPRIME (s : string) ;
var
  i, z : integer;
begin
  if ( VACIA ) then
    writeln ('la cola esta vacia')
  else begin
    if length (s) > 0 then writeln (s);
    write ('cola: ');
    i := ant;
    z := SUMA_UNO (post);
    while (i <> z) do begin
      write (elementos [i],' ');
      i := SUMA_UNO (i);
    end ; {while}
    writeln ;
  end ; {while}
end;

end.
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}

Generated by GNU enscript 1.6.1.