Está en la página 1de 1

Dicotmica en Archivos

VAR
a : file of integer;
num, numi, numj, valor, i, j, aux, inf, sup, med : integer;
band : boolean;
CARGA
if not eof(a)
V

seek (a, filesize(a))


writeln ('ingrese un numero <> 0')
readln (num);
while num <> 0
write (a, num)
readln (num)

DICOTOMICA
ORDENA

writeln('ingrese valor a buscar')

reset (a)

readln (valor)

for I := 0 to filesize(a)-2

reset (a)

for j := i+1 to filesize(a)-1

sup := filesize(a)-1

seek (a , i)

inf :=0

read (a , numi)

band := false

seek (a , j)

while (not(eof(a))) and (inf <= sup) and (band=false)

read (a , numj)

med := (inf + sup) div 2

numi > numj


V

seek ( a , med)
F

read ( a , num);

seek (a, i)

num = valor

write (a , numj)

seek (a , j)

band:= true

num > valor

write (a , numi)

sup := med - 1
V

Prof. Claudia Dania

inf := med + 1

valor = num

writeln
('encontrado', MED,
es la posicion)

writeln
('NO esta en el archivo')

También podría gustarte