Ir ao conteúdo
  • Cadastre-se

Probelma ao Excluir em uma Lista Duplamente encadeada , Ajuda aee =D


rasarib

Posts recomendados

Bom dia !! e o seguinte estou tendo um problema , na procedure excluirFilme , queria uma ajuda para solucionar este problema ...

vlwss aí

segue o codigo :


program trabalhoAv2;

uses crt;

type
bloco = ^no;
filme = record

nomeDoFilme:String;
genero:String;
diretor:String;

end;
no = record
info:filme;
dir,esq:bloco;
end;

var
inicio,fim,aux:bloco;
option: integer;
nome,diretor,genero:string;
{ ====================== Criar ========================= }
procedure criar;
begin
inicio := nil;
fim := nil;
end;

{======================= Verificar ============================= }
function verificar : boolean;
begin
verificar := ( inicio = nil );
end;

{ ======================== Pesquisar por nome ======================= }

function pesquisarPorNome(nome:string):filme;

var
numero:integer;

begin
aux := inicio;
numero := 0;
gotoxy(8,18);
writeln;
while ( aux <> nil ) do
begin
if ( aux^.info.nomeDoFilme = nome ) then
begin
writeln(' =====================================================');

writeln(' NOME DO FILME : ' , aux^.info.nomeDoFilme);

writeln(' GENERO : ', aux^.info.genero);

writeln(' DIRETOR : ' , aux^.info.diretor);

writeln(' =====================================================');
numero := numero +1;
pesquisarPorNome := aux^.info;
end;

aux := aux^.dir;
end;
if ( numero = 0 ) then
begin
writeln(' NENHUM FILME CADASTRADO COM ESTE NOME !');
end;
end;

{ ======================== Pesquisar por genero ======================= }

procedure pesquisarPorGenero(genero:string);

var
numero:integer;

begin
aux := inicio;
numero := 0;

gotoxy(8,18);
writeln;

while ( aux <> nil ) do
begin
if ( aux^.info.genero = genero ) then
begin
writeln(' ======================================================');

writeln(' NOME DO FILME : ' , aux^.info.nomeDoFilme);

writeln(' GENERO : ', aux^.info.genero);

writeln(' DIRETOR : ' , aux^.info.diretor);

writeln(' ======================================================');
numero := numero+1;
end;

aux := aux^.dir;
end;
if ( numero = 0 ) then
begin
writeln(' NENHUM FILME CADASTRADO COM ESTE GENERO ! ');
end;
end;

{ ======================== Pesquisar por diretor ======================= }

procedure pesquisarPorDiretor(diretor:string);

var
numero : integer;
begin
aux := inicio;
numero := 0;
gotoxy(8,18);
writeln;

while ( aux <> nil ) do
begin
if ( aux^.info.diretor = diretor ) then
begin
writeln(' =====================================================');

writeln(' NOME DO FILME : ' , aux^.info.nomeDoFilme);

writeln(' GENERO : ', aux^.info.genero);

writeln(' DIRETOR : ' , aux^.info.diretor);

writeln(' =====================================================');
numero := numero+1;
end;

aux := aux^.dir;
end;
if ( numero = 0 ) then
begin
writeln(' NENHUM FILME CADASTRADO COM ESTE DIRETOR ! ');
end;
end;


{ ===================== CADASTRAR ================= }

procedure cadastrar;

var
cad : filme;
c:integer;
begin

c := 0001;
gotoxy(3,14);textcolor(red+blink);
writeln(' CADASTRAR ' );

textcolor(7);
textbackground(2);
gotoxy(3,15);
writeln(' ===================================================');

gotoxy(3,16);
writeln('| CODIGO : ',c,' |');

gotoxy(3,18);
writeln('| NOME DO FILME : |' );

gotoxy(3,20);
writeln('| GENERO : |');


gotoxy(3,22);
writeln('| DIRETOR : |');
writeln;

gotoxy(3,23);
writeln(' ===================================================');

gotoxy(21,18);readln(cad.nomeDoFilme);
gotoxy(14,20);readln(cad.genero);
gotoxy(15,22);readln(cad.diretor);

new(aux);
aux^.info := cad ;
if ( verificar = true ) then
begin
aux^.dir := nil;
aux^.esq := nil;
inicio := aux;
fim := aux;
end
else
begin
aux^.esq := nil;
aux^.dir := inicio;
inicio^.esq := aux;
inicio := aux;
end;
gotoxy(3,24);writeln(' CADASTRO REALIZADO COM SUCESSO ! ');
readkey;

end;
{ ====================== Remover um Filme ==========================}
procedure excluirFilme( nome : string );


begin
aux^.info := pesquisarPorNome(nome);

if ( aux = nil ) then
begin
gotoxy(3,20);textcolor(red);
writeln('NAO EXISTE FILME CADASTRADO !!! ');
textcolor(2);
end
else
begin
if (aux = inicio) then
begin
inicio := inicio^.dir;
aux^.dir := nil;
inicio^.esq := nil;
dispose(aux);
end
else
begin
if ( aux = fim ) then
begin
fim := fim^.esq;
fim^.dir := nil;
aux^.esq := nil;
dispose(aux);
end
else
begin
aux^.esq^.dir := aux^.dir ;
aux^.dir^.esq := aux^.esq ;
aux^.dir := nil;
aux^.esq := nil;
dispose(aux);
end;
end;
end;
end;
{ ================ Listar todos os filmes ============= }

procedure listarFilmes;

begin
clrscr;
textcolor(7);
gotoxy(10,1);
writeln('##########################################');

gotoxy(10,3);
textcolor(red+blink);
writeln('# LISTA DE FILMES CADASTRADOS #');

textcolor(7);

aux := inicio;
gotoxy(4,5);
writeln;
if ( aux = nil ) then
writeln(' NAO EXISTE NENHUM FILME CADASTRADO !!! ' );

while aux <> nil do
begin
writeln(' ==========================================');

writeln(' NOME DO FILME : ' , aux^.info.nomeDoFilme);

writeln(' GENERO : ', aux^.info.genero);

writeln(' DIRETOR : ' , aux^.info.diretor);

writeln(' ==========================================');
aux := aux^.dir;
end;
readkey;

end;



{ =============== PROGRAMA PRINCIPAL ==================== }
begin
clrscr;
textbackground(2);
criar;

while( option <> 6 ) do
begin
clrscr;
textcolor(7);
writeln(' =====================================================');
gotoxy(3,2);textcolor(red+blink);
writeln('+ LOCADORA INSERCTENTER +');
textcolor(7);
writeln(' =====================================================');

writeln;
writeln;
writeln(' SELECIONE UMA OPCAO ');
writeln(' [1] Cadastrar ' );
writeln(' [2] Pesquisar filme ' );
writeln(' [3] Alterar filme ' );
writeln(' [4] Excluir filme ' );
writeln(' [5] Listar filmes ' );
writeln(' [6] Finalizar sistema ' );

gotoxy (35,8);
textcolor(red);
textbackground(white);

gotoxy (35,9);
writeln('==============');

gotoxy (35,10);
writeln('| OPCAO = |' );

gotoxy (35,11);
writeln('==============');

gotoxy (45,10);
readln(option);
textcolor(7);
textbackground(2);

case (option) of
1: begin
cadastrar;
end;
2: begin
textbackground(2);
clrscr;
textcolor(7);
gotoxy(8,1);
writeln('########################################################');

gotoxy(8,3);
textcolor(red+blink);
writeln('# MENU DE PESQUISA #');

textcolor(7);
writeln;

gotoxy(8,5);
writeln('[1] PESQUISAR POR NOME ');

gotoxy(8,6);
writeln('[2] PESQUISAR POR GENERO');

gotoxy(8,7);
writeln('[3] PESQUISAR POR DIRETOR');

gotoxy(8,8);
writeln('[4] VOLTAR AO MENU PRINCIPAL');

gotoxy(8,10);
textcolor(red+blink);
writeln(' SELECIONE O MODO DE PESQUISA : ' );
gotoxy(40,10);readln(option);
textcolor(7);

case (option) of
1: begin
gotoxy(8,13);writeln('=====================================================');
gotoxy(8,15);writeln('| DIGITE O NOME DO FILME : |');
gotoxy(8,17);writeln('=====================================================');
gotoxy(35,15);readln(nome);
pesquisarPorNome(nome);
end;

2: begin
gotoxy(8,13);writeln('=====================================================');
gotoxy(8,15);writeln('| DIGITE O GENERO DO FILME : |');
gotoxy(8,17);writeln('=====================================================');
gotoxy(38,15);readln(genero);
pesquisarPorGenero(genero);
end;

3: begin
gotoxy(8,13);writeln('=====================================================');
gotoxy(8,15);writeln('| DIGITE O NOME DO DIRETOR : |');
gotoxy(8,17);writeln('=====================================================');
gotoxy(37,15);readln(diretor);
pesquisarPorDiretor(diretor);
end;

4: begin
textbackground(2);
clrscr;
end;
else
begin
textbackground(2);
textcolor(7);
gotoxy(8,13);writeln('=====================================');
gotoxy(8,14);writeln('| OPCAO INVALIDA , TENTE NOVAMENTE |' );
gotoxy(8,15);writeln('=====================================');
readkey;
end;
end;
readkey;
end;
// 3: alterarFilme();
4: begin
gotoxy(3,14);writeln('=====================================================');
gotoxy(3,16);writeln('| DIGITE O NOME DO FILME : |');
gotoxy(3,18);writeln('=====================================================');
gotoxy(30,16);readln(nome);
excluirFilme(nome);
end;
5: begin
textbackground(2);
listarFilmes;
end;
6: begin
gotoxy(3,15);
writeln('PRESSIONE QUALQUER TECLA PARA FINALIZAR...');
option := 6;
end
else
gotoxy(3,15);
textcolor(7);
textbackground(2);
writeln('OPCAO INVALIDA , TENTE NOVAMENTE. ' );
readkey;
end;
end;
readkey;

end.


Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!