# EXEMPLO DE REMOÇÃO ARVORE 5 24 3 68 7. if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then.

## Presentation on theme: "EXEMPLO DE REMOÇÃO ARVORE 5 24 3 68 7. if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then."— Presentation transcript:

EXEMPLO DE REMOÇÃO ARVORE 5 24 3 68 7

if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=5 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=3 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=2 ROTINA PARA REMOVER O ELEMENTO 2 ELEMENTO 2 REMOVIDO

if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=5 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=3 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=4 ROTINA PARA REMOVER O ELEMENTO 4 ELEMENTO 4 REMOVIDO

if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=5 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=3 if (T = nil) then begin writeln ('ELEMENTO NAO ENCONTRADO NA ARVORE'); end else begin if (X.ch < T^.elem.ch) then begin remove (T^.esq, X); end else begin if (X.ch > T^.elem.ch) then begin remove (T^.dir, X); end else begin if (T^.dir = nil) then begin A := T; T := T^.esq; dispose(A); end else begin if (T^.esq=nil) then begin A := T; T := T^.dir; dispose(A); end else begin Maior (T^.esq,X); T^.elem := X ; remove (T^.esq,X ); end; T=2 procedure maior (Q:arvore; var R:Telemento); begin while Q^.dir <> nil do begin Q:= Q^.dir; end; R:= Q^.elem; end; T=2 ROTINA PARA REMOVER O ELEMENTO 3 ELEMENTO 3 REMOVIDO

Similar presentations