Você está na página 1de 6

5lista_completaok.

pas {Inserir um elemento no final com lista} program lista_completa; uses crt; type tipoDado = integer; tipo_ponteiro_NODO = ^tipoNODO; tipoNODO = record Dado:tipoDado; Prox :tipo_ponteiro_NODO; end; procedure menu; begin clrscr; writeln('1 writeln; writeln('2 writeln; writeln('3 writeln; writeln('4 writeln; writeln('5 writeln; writeln('6 writeln; writeln('7 writeln; writeln('8 writeln; writeln('9 end;

- Insere NODO no inicio'); - Insere NODO no final'); - Insere NODO no n-esimo'); - Retira NODO do inicio'); - Retira NODO do final'); - Retira NODO no n-esimo'); - Pesquisa NODO'); - Exibe LISTA'); - SAIR');

procedure cria_ponteiro(var p, q:tipo_ponteiro_NODO); begin new(p); p := nil; new(q); q := nil; end; {---Opcao 1---} procedure InsereInicio(var p:tipo_ponteiro_NODO; Valor :tipoDado); var q, aux: tipo_ponteiro_NODO; begin new(aux); aux^.dado := valor; if p = nil then aux^.prox := nil else begin aux^.prox := p; p := aux; end; end; {---Opcao 2---} procedure InsereFim(var p:tipo_ponteiro_NODO; Valor :tipoDado); var q, aux: tipo_ponteiro_NODO; begin new(aux); aux^.Dado:=Valor; aux^.Prox:=nil; if p = nil then p:= aux Pgina 1

5lista_completaok.pas else begin q:= p; while q^.Prox <> nil do q:=q^.Prox; q^.Prox:=aux; end; end; {---Opcao 3---} procedure insereNesimo(var p:tipo_ponteiro_NODO; Pos :tipoDado); var q, aux: tipo_ponteiro_NODO; valor : integer; begin new(q); new(aux); if p = nil then writeln('LISTA VAZIA ou Posicao nao existe') else begin q:= p; while q^.Prox <> nil do begin if q^.dado = pos then begin write('Digite um valor inteiro: '); readln(valor); aux^.dado := valor; aux^.prox := q^.prox; q^.prox := aux; break; end; q:=q^.Prox; end; {q^.Prox:=aux;} end; end; {---Opcao 4---} procedure RetiraInicio(var p:tipo_ponteiro_NODO); var q : tipo_ponteiro_NODO; begin new(q); if p = nil then writeln('LISTA VAZIA') else begin q := p^.prox; p := q; end; end; {---Opcao 5---} procedure RetiraFim(var p:tipo_ponteiro_NODO); var q, aux : tipo_ponteiro_NODO; begin new(q); new(aux); if p = nil then writeln('LISTA!! VAZIA') else begin q := p; while q^.prox <> nil do begin aux := q; q := q^.prox; end; aux^.prox := nil; end; Pgina 2

5lista_completaok.pas end; {---Opcao 6---} procedure RetiraNesimo(var: p:tipo_ponteiro_NODO; pos:tipodados); var q, aux : tipo_ponteiro_NODO; begin exibelista(p); new(q); new(aux); if p = nil then writeln ('LISTA VAZIA'); else begin writeln('Digite o Nodo a ser Retirado'); read(aux^.prox {---exibir lista---} procedure exibeLista(p:tipo_ponteiro_NODO); var q : tipo_ponteiro_NODO; begin if p = nil then writeln('LISTA VAZIA!!') else begin writeln; write('Lista : '); q := p; while q <> nil do begin write(q^.dado:5); q := q^.prox; end; end; end; {---Opcao 7---} procedure pesquisaLista(p:tipo_ponteiro_NODO; valor: tipodado; var resp:boolean); var q : tipo_ponteiro_NODO; begin if p = nil then writeln('LISTA VAZIA') else begin writeln; write('Lista : '); q := p; while q <> nil do begin textcolor(15); if q^.dado = valor then begin textcolor(14); resp := true; end; write(q^.dado:5); textcolor(15); q := q^.prox; end; end; end;

{---Programa Principal---} var p,q, aux: tipo_ponteiro_NODO; Pgina 3

5lista_completaok.pas valor, pos : integer; op : byte; resp:boolean; begin clrscr; cria_ponteiro (p, q); repeat menu; writeln; write('Opcao: '); readln(op); if op = 9 then break; case op of 1: begin repeat clrscr; writeln; writeln('INSERE NODO NO INICIO'); exibelista(p); writeln; write('Digite um valor inteiro (-1 para sair): '); readln(valor); if valor = -1 then break; insereInicio(p,valor); exibelista(p); readkey; until false; end; 2: clrscr; writeln; writeln('INSERE NODO NO FIM'); writeln; write('Digite um valor inteiro (-1 para sair): '); readln(valor); if valor = -1 then break; insereFim(p,valor); exibelista(p); readkey; until false; end; 3: begin repeat clrscr; writeln; writeln('INSERE NODO APOS O N-ESIMO'); writeln; write('Digite apos qual NODO deseja inserir (-1 para sair): '); readln(pos); if pos = -1 then break; insereNesimo(p,pos); exibelista(p); readkey; until false; end; 4: begin clrscr; writeln; writeln('RETIRA NODO DO INICIO'); Pgina 4 begin repeat

5lista_completaok.pas exibelista(p); writeln; retiraInicio(p); exibelista(p); readkey; end; 5:begin clrscr; writeln; writeln('RETIRA NODO DO FIM'); exibelista(p); writeln; retiraFim(p); exibelista(p); readkey; end; 6: {begin repeat clrscr; writeln; writeln('RETIRA O N-ESIMO'); writeln; write('Digite apos qual NODO deseja retirar (-1 para sair): '); readln(pos); if pos = -1 then break; retiraNesimo(p,pos); exibelista(p); readkey; until false; end; } write('em construco'); begin repeat clrscr; writeln; writeln('PESQUISA NODO'); writeln; write('Digite um valor inteiro (-1 para sair): '); readln(valor); if valor = -1 then break; resp := false; pesquisaLista(p,valor, resp); writeln; writeln; if resp = true then writeln('Valor encontrado(destaque em amarelo)') else writeln('Valor nao pertence a LISTA'); readkey; until false; end; 8: exibelista(p); else writeln('Opcao invalida'); end; writeln; gotoxy(1,23);write('Pressione qualquer tecla...'); readkey; until op = 9; writeln; gotoxy(1,23);write('Fim do programa...'); readkey; Pgina 5 7:

5lista_completaok.pas end.

Pgina 6

Você também pode gostar