La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

Type tipo_bf = -1..+1; tipo_dato = word; tipo_puntero = ^tipo_nodo; tipo_nodo = record dato: tipo_dato; izquierdo, derecho: tipo_puntero; bf: tipo_bf;

Presentaciones similares


Presentación del tema: "Type tipo_bf = -1..+1; tipo_dato = word; tipo_puntero = ^tipo_nodo; tipo_nodo = record dato: tipo_dato; izquierdo, derecho: tipo_puntero; bf: tipo_bf;"— Transcripción de la presentación:

1 Type tipo_bf = -1..+1; tipo_dato = word; tipo_puntero = ^tipo_nodo; tipo_nodo = record dato: tipo_dato; izquierdo, derecho: tipo_puntero; bf: tipo_bf; End; Clave

2 Procedure Buscar(d: tipo_dato; var p: tipo_puntero; var aumenta_alt: boolean; var ex: boolean); Var p1, p2: tipo_puntero; Begin If p = nil Then {La clave no está en el árbol->insertar} Begin New(p); aumenta_alt := true; ex := false; With p^ Do Begin dato := d; izquierdo := nil; derecho := nil; bf := 0; End; End Else […] Else Begin aumenta_alt := false; ex := true; End End; 5 7 Nil

3 R ID R I D R I D Else If d < p^.dato Then Begin Buscar(d, p^.izquierdo, aumenta_alt, ex); If aumenta_alt Then{El subárbol izquierdo ha crecido} Case p^.bf of +1:Begin {El peso se ha desplazado a la izquierda} p^.bf := 0; aumenta_alt := false; End; 0: p^.bf := -1; -1:Begin p1 := p^.izquierdo; If p1^.bf = -1 Then Begin { Rotacion II } […] End Else Begin { Doble Rotacion LR } […] End; aumenta_alt := false; End; { Del +1 } End; { Del case } End { Del If d < p^.dato}

4 p1 := p^.izquierdo; If p1^.bf = -1 Then Begin { Rotacion LL } p^.izquierdo := p1^.derecho; p1^.derecho := p; p^.bf := 0; p1^.bf := 0; p := p1 End

5 Else Begin { Rotacion LR } p2 := p1^.derecho; p1^.derecho := p2^.izquierdo; p2^.izquierdo := p1; p^.izquierdo := p2^.derecho; p2^.derecho := p; If p2^.bf = -1 Then p1^.bf := +1 Else p1^.bf := 0; If p2^.bf = +1 Then p^.bf := -1 Else p^.bf := 0; p2^.bf := 0; p := p2; End; p1 p2

6 8 410 26 1 B A 0 0 8 4 26 1 0 0 0 0 0 0 8 410 26 1 0 0 8 410 26 1 0 0 Caso 1 -1:Begin p1 := p^.izquierdo; If p1^.bf = -1 Then […]

7 8 410 26 7 0 0 8 4 26 7 0 0 0 0 0 0 8 410 26 0 1 0 8 410 26 1 0 Caso 2 C A B 7 0 7

8 Begin { Del Procedimiento Borrar } If p = nil Then Begin Write('El dato ', d, ' no esta en el arbol'); dismin_alt := false; End Else If d < p^.dato Then Begin Borrar(d, p^.izquierdo, dismin_alt); If dismin_alt Then Equilibrar_Izquierdo(p, dismin_alt); End Else If d > p^.dato Then Begin Borrar(d, p^.derecho, dismin_alt); If dismin_alt Then Equilibrar_Derecho(p, dismin_alt); End Else ENCONTRADO!!!!! […] End; { Del Procedimiento Borrar}

9 Else {ENCONTRADO!!!!!} Begin q := p; If q^.derecho = nil Then Begin p := q^.izquierdo; dismin_alt := true; End Else If q^.izquierdo = nil Then Begin p := q^.derecho; dismin_alt := true; End Else Begin Bor(q^.izquierdo, dismin_alt); If dismin_alt Then Equilibrar_Izquierdo(p, dismin_alt); End; Dispose(q); End; End; { Del Procedimiento Borrar} El nodo borrado será reemplazado por el nodo del hijo izquierdo que se encuentre más a la derecha 8 410 26 7 11 8 4 8 10

10 Procedure Bor(var r: tipo_puntero; var dismin_alt: boolean); Begin If r^.derecho <> nil Then Begin Bor(r^.derecho, dismin_alt); If dismin_alt Then Equilibrar_Derecho(r, dismin_alt); End Else Begin p^.dato := r^.dato; q := r; r := r^.izquierdo; dismin_alt := true; End;

11 Procedure Equilibrar_Derecho(var p: tipo_puntero; var dismin_alt: boolean); Var p1, p2: tipo_puntero; e1, e2: tipo_bf; Begin Case p^.bf of +1: p^.bf := 0; 0:Begin p^.bf := -1; dismin_alt := false; End; -1: Begin p1 := p^.derecho; e1 := p1^.bf; If e1 <= 0 Then Begin { Rotacion RR } […] End Else Begin { Rotacion RL } […] End; End; { Del Procedimiento Equilibrar_Izquierdo }


Descargar ppt "Type tipo_bf = -1..+1; tipo_dato = word; tipo_puntero = ^tipo_nodo; tipo_nodo = record dato: tipo_dato; izquierdo, derecho: tipo_puntero; bf: tipo_bf;"

Presentaciones similares


Anuncios Google