alguien me puede ayudar??
Publicado por Amanda (1 intervención) el 27/04/2004 14:24:48
Tengo este algoritmo, que creo es Ada y tengo que llevarlo al lenguaje Pascal., pero hay sentencias que desconozco, como el discrete, new, wtih. Si alguien puede explicarmelas, lo agradezco o dónde puedo consultar dichas sentencias, ya que he bajado tutoriales y no las encuentro. Aquí va, gracias
1 function fibonacci_search(item: integer; arr: sort_array) return index
2 is
3 l : index := arr'first; -- first element of array
4 u : index := arr'last; -- last element of array
5 m : index := (u+l)/2;
6 x,a,b : integer;
7 begin
8 a := (Fn-3);
9 b := (Fn-2)-(Fn-3);
10 discrete (f2,f1) := (Fn-2,Fn-3)
11 new (f2,f1) := (f2-f1,2*f1-f2) | (a,b)
12 with i := u-l+1
13 new i=i/2 loop
14 loop
15 if item < arr(m) then
16 m := m-f1; -- compute new position of compared element
17 f2 := f2-f1;
18 f1 := f1-f2;
19 elsif item > arr(m) then
20 m := m+f1; -- compute new position of compared element
21 x := f1;
22 f1 := f2-f1;
23 f2 := x;
24 a := f2; b := f1;
25 else
26 return m; -- return index of found item
27 end if;
28 i := i/2;
29 end loop;
30 end fibonacci_search;
1 function fibonacci_search(item: integer; arr: sort_array) return index
2 is
3 l : index := arr'first; -- first element of array
4 u : index := arr'last; -- last element of array
5 m : index := (u+l)/2;
6 x,a,b : integer;
7 begin
8 a := (Fn-3);
9 b := (Fn-2)-(Fn-3);
10 discrete (f2,f1) := (Fn-2,Fn-3)
11 new (f2,f1) := (f2-f1,2*f1-f2) | (a,b)
12 with i := u-l+1
13 new i=i/2 loop
14 loop
15 if item < arr(m) then
16 m := m-f1; -- compute new position of compared element
17 f2 := f2-f1;
18 f1 := f1-f2;
19 elsif item > arr(m) then
20 m := m+f1; -- compute new position of compared element
21 x := f1;
22 f1 := f2-f1;
23 f2 := x;
24 a := f2; b := f1;
25 else
26 return m; -- return index of found item
27 end if;
28 i := i/2;
29 end loop;
30 end fibonacci_search;
Valora esta pregunta
0