Índice > Lista > Estática Seqüencial > Resolução dos Exercícios

Instituto de Ciências Matemáticas de São Carlos
Departamento de Computação e Estatística
SCE182 - Algorítmos e Estruturas de Dados 1
Profs. Resp.: Graça Pimentel e Maria Cristina

Resolução dos Exercícios

Programa que manipula listas sequencias, utiliza-se Unit Lista1 - onde os procedimentos estão armazenados.

Program L1call;

Uses lista1, Crt;

Type alfabeto= 'a'..'g';
Var L1, L2, L3: lista;
    Lc: listaC;
    elem: Telem;
    opt: char;

begin
  Create(L1);
  Create(L2);
  Create(L3);
  CreateC(Lc);
  Repeat
     ClrScr;
     writeln('Entre com opcao desejada:');
     writeln;
     writeln('a = verifique ordem');
     writeln('b = copia L1 em L2');
     writeln('c = copia L1 em L2 eliminando elementos repetidos');
     writeln('d = inverta L1 colocando resultado em L2');
     writeln('e = intercale L1 e L2 em L3');
     writeln('f = gere L2 contando os elementos de L1');
     writeln('g = elimine todos os "elem" de L1');
     writeln('h = insira em L1 um elemento dado');
     writeln('i = nro elem, maior, menor, maior freq e menor freq');
     writeln('F = fim');
     readln(opt);
     writeln;
     writeln;
     write('Funcao pedida: ');
     case opt of
     'a': begin
            writeln('a = verifique ordem');
            leia(L1); chk_order(L1);
          end;
     'b': begin
            writeln('b = copia L1 em L2');
            leia(L1); copy_all(L1, L2); imprima(L2);
          end;
     'c': begin
            writeln('c = copia L1 em L2 eliminando elementos repetidos');
            leia(L1);
            if not empty(L1) then
              begin
                copy_clean(L1, L2); imprima(L2);
              end;
          end;
     'd': begin
            writeln('d = inverta L1 colocando resultado em L2');
            leia(L1); invert(L1, L2); imprima(L2);
          end;
     'e': begin
            writeln('e = intercale L1 e L2 em L3');
            leia(L1); leia(L2); merge(L1,L2,L3); imprima(L3);
          end;
     'f': begin
            writeln('f = gere L2 contando os elementos de L1');
            leia(L1); count_elem(L1, Lc); imprimaLc(Lc);
          end;
     'g': begin
            writeln('g = elimine todos os "elem"  de L1');
            leia(L1);
            if not empty(L1) then
              begin
               leia_elem(elem); remove_all_elem(L1, elem);
              end;
            imprima(L1);
          end;
     'h': begin
            writeln('h = insira em L1 um elemento dado');
            leia(L1); leia_elem(elem); insere_elem(L1, elem);
            imprima(L1);
          end;
     'i': begin
            writeln('i = nro elem, maior, menor, maior freq e menor freq');
            leia(L1);
            if not empty(L1) then
              begin
                nro_elem(L1);
                maior_menor(L1); chk_freq(L1);
              end;
           end;
     'F':  begin
             writeln('F=FIM');
           end;
    end;
  writeln;
  writeln('Aperte  para continuar');
  readln;
  Until opt = 'F';
end.