{
------------------------------------------------------------------------------- 
Autor: Jan Kohlhof
Email: kohj@hrz.tu-chemnitz.de
-------------------------------------------------------------------------------
} 

UNIT queue;

INTERFACE
type mytype=integer;
     liste=^element;
     element= record
     		data:mytype;
		next:liste;
	      end;
     queue=record
	    first,last:liste;
	   end;

procedure init(var p:queue);
procedure put(var p:queue;x:mytype);
function  get(var p:queue):mytype;
function  isempty(p:queue):boolean;

IMPLEMENTATION

procedure init(var p:queue);
 begin
  p.first:=nil;
  p.last:=nil;
 end;

function isempty(p:queue):boolean;
 begin
  isempty:=((p.first=nil) and (p.last=nil));
 end;

procedure put(var p:queue;x:mytype);
var q:liste;
 begin
  new(q);
  q^.data:=x;
  q^.next:=p.first;
  p.first:=q;
 end;

function get(var p:queue):mytype;
var q:liste;
 begin
  if not(isempty(p)) then
   begin
    q:=p.first;
    while q^.next<>p.last DO q:=q^.next;
    get:=p.last^.data;
    dispose(p.last);
    p.last:=q;
   end
  else writeln('queue ist leer!');
 end;

begin
end.