-->

Seguidores

Tecnologia do Blogger.
Cursos Online na Área de Informática
Siga-nos
Twitter Facebook RSS
sexta-feira, 21 de outubro de 2011
Program Pzim ;
 const max = 7;
 type Fila = record
  dados : array[1..max]of string;
      inicio, fim : integer;
     end;
 

         ListEnc = ^No;
 
No = record
                  obj: String;
                  prox: ListEnc;
             end;
var
  L :ListEnc;
     f1 : Fila;
     v: string;
   
 procedure criar(var F:Fila);
 begin
     F.inicio := 1;
     F.fim := 1;
 end;

 function filaVazia(F:Fila):boolean;
 begin
     if F.inicio = F.fim then
      filaVazia := true
     else
      filaVazia := false;
 end;

 function filaCheia(F:Fila):boolean;
 begin
     if F.fim > max then
      filaCheia := true
     else
      filaCheia := false;
 end;

 procedure enqueue(var F:Fila;s:string);
 begin
     if filaCheia(F)then
      writeln('A fila tá cheia!')
     else
     begin
         F.dados[F.fim] := s;
         F.fim := F.fim + 1;
         writeln('Inserção efetuada!')
     end;
 end;

 function dequeue(var F:Fila):string;
 begin
     if filaVazia(F)then
      writeln('A fila tá vazia!')
     else
     begin
      dequeue := F.dados[F.inicio];
      F.inicio := F.inicio + 1;
     end;
 end;

 procedure mostrarFila(F:Fila);
 begin
     if filaVazia(F)then
      writeln('A fila tá vazia!')
     else
     begin
      while not filaVazia(F)do
write(dequeue(F),'|');
     end;
     writeln;
 end;
   procedure Lcriar(var L:ListEnc);
         begin
             L := nil;
         end;
       
   //INFORMA SE A LISTA ESTÁ VAZIA OU NÃO
         function vazia(L: ListEnc):boolean;
         begin
             if L = nil then
                vazia := true
             else
                vazia := false;
         end;

         //INSERE UM ELEMENTO NA LISTA
         procedure inserir(var L: ListEnc; s: string);
         var
            N, P: ListEnc;
          begin
            new(N);
            N^.obj := s;
            if vazia(L)then
               begin
                    N^.prox := L;
                    L := N;
               end
           else
  begin
          P := L;
          while (P^.prox <> nil)do
                          P := P^.prox;
          N^.prox := P^.prox;
          P^.prox := N;
  end;
  end;
 
//REMOVE UM ELEMENTO DA LISTA
          function remover(var L: ListEnc; s: string):boolean;
          var
            P, Q: ListEnc;
          begin
           if vazia(L)then
              remover := false
           else
            if (L^.obj = s)then
            begin
              P := L;
              L := L^.prox;
              dispose(P);
              remover := true;
            end
            else
               begin
                P := L;
                    while ((P^.prox <> nil)and (P^.prox^.obj <> s)) do
                    begin
                        P := P^.prox;
                    end;
                    if (P^.prox <> nil) and (P^.prox^.obj = s) then
                    begin
                         Q := P^.prox;
                         P^.prox := Q^.prox;
                         dispose(Q);
                         remover := true;
                    end
                    else
                    begin
                        remover := false;
                    end;
end;        
end;

         // IMPRIME A LISTA
         procedure imprimir(L: ListEnc);
         var
            P: ListEnc;
         begin
            if vazia(L)then
               writeln('LISTA VAZIA!!!')
            else
            begin
                P := L;
                while (P <> nil) do
                begin
write(P^.obj,' | ');
                     P := P^.prox;
                end;
            end;
         end;    

 Begin
     textcolor(white);
criar(f1);
Lcriar(L);
     writeln('A fila está vazia? ', filaVazia(f1));
     writeln('A fila está cheia? ', filaCheia(f1));
     enqueue(f1,'Macaco');
     enqueue(f1,'Cachorro');
     enqueue(f1,'Gato');
     enqueue(f1,'Coruja');
     enqueue(f1,'Cobra');
     enqueue(f1,'Porco');
    while not filaVazia(f1) do
     begin
 v := dequeue(f1);
       inserir(L, v);
     end;
     writeln ('imprimindo a lista');
 imprimir(L);
     readln;
 End.
Gostou? Compartilhe!

0 comentários:

Seu Sistema Operacional é...

TEMAS

Visualizações