Pascal/Turbo Pascal - Arboles y archivos

 
Vista:

Arboles y archivos

Publicado por Juan (20 intervenciones) el 10/10/2013 20:52:37
Problema: Dado un arbol binario ordenado, de enteros, se pide que: genere un archivo tambien ordenado con los numeros del arbol en los niveles 4 y 6. No se pueden utilizar estructuras auxiliares (si variables). Y los niveles del arbol son: nivel 1 raiz, nivel 2 hijos de la raiz y asi sucesivamente
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Arboles y archivos

Publicado por ramon (2158 intervenciones) el 11/10/2013 16:34:47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{A ver si esto te ayuda }
 
program abolarchiv;
 uses
  crt;
 type
  elarbol = ^elnodo;
  elnodo = record
       valor : Integer;
    izq, der : elarbol;
  end;
 
 const
     nomarchi = 'arbolord.arb';
 
 var
   f : file of integer;
   det : integer;
   aux, nodo : elarbol;
 
 
 procedure hayarchivo;
 begin
    assign(f,nomarchi);
    {$I-} reset(f); {$I+}
      if ioresult = 0 then
      begin
         close(f);
         erase(f);
      end;
  end;
 
 procedure tomavalores(p : integer);
 begin
      assign(f,nomarchi);
    {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
          rewrite(f);
          seek(f,0);
          write(f,p);
          close(f);
      end
   else
       begin
          seek(f,filesize(f));
          write(f,p);
          close(f);
       end;
   end;
 
 procedure Guardainorde(a : elarbol);
 begin
  if a <> nil then
  begin
    Guardainorde(a^.izq);
    tomavalores(a^.valor);
    Guardainorde(a^.der);
  end;
 end;
 
 procedure presentainorden(a : elarbol);
 begin
  if a <> nil then
  begin
    presentainorden(a^.izq);
    write(' ',a^.valor);
    presentainorden(a^.der);
  end;
 end;
 
 procedure insertar(var a : elarbol; va : Integer);
 begin
    if a = nil then
    begin
       new(a);
       a^.valor := va;
       a^.izq := nil;
       a^.der := nil;
     end
  else
     if a^.valor < va then
     insertar(a^.der, va)
  else
     insertar(a^.izq, va);
  end;
 
   procedure entradavalores(var n : elarbol);
   var
      nl : integer;
   begin
         writeln('*** Entrando [0] Termina Entradas ****');
         writeln;
       repeat
            write('   Entre Numero Entero : ');
       {$I-} readln(nl); {$I+}
       if ioresult <> 0 then
       begin
       write('Solo Valores Numericos');
       nl := 1000;
       writeln;
       end
     else
         if (nl > 0) and (nl < 999) then
         insertar(n,nl);
       until nl = 0;
    end;
 
  procedure cargaarchivo;
  var
     d, t : longint;
     da : integer;
  begin
      assign(f,nomarchi);
    {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
          writeln('   Error De Archivo Pulse Una Tecla');
          readkey;
      end
    else
       begin
          t := filesize(f) - 1;
          da := 0;
          d := 0;
          nodo := nil;
       repeat
           seek(f,d);
           read(f,da);
           insertar(nodo,da);
           d := d + 1;
       until d > t;
       close(f);
       end;
  end;
 
  procedure menu;
  var
     tecla : char;
     sal : boolean;
  begin
     sal := false;
   repeat
       clrscr;
       writeln('   ***** Memu Jeneral *****');
       writeln;
       writeln('   0 = Limpiar Archivo');
       writeln('   1 = Entrada Valores');
       writeln('   2 = Guarda Valores');
       writeln('   3 = Carga De Disco');
       writeln('   4 = Ver Arbol');
       writeln('   5 = Salir');
       writeln;
       writeln('   <<<<< Elija Opcion >>>>>');
    repeat
        tecla := readkey;
    until tecla in['0','1','2','3','4','5'];
    clrscr;
    case tecla of
  '0' : begin hayarchivo; end;
  '1' : begin entradavalores(nodo);  end;
  '2' : begin Guardainorde(nodo);  end;
  '3' : begin cargaarchivo; end;
  '4' : begin presentainorden(nodo); readkey; end;
  '5' : sal := true;
    end;
   until sal = true;
  end;
begin
      nodo := nil;
      menu;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Arboles y archivos

Publicado por fede (1 intervención) el 08/10/2014 20:42:22
Disculpame y la parte que te pide el ejercicio de solamente los niveles 4 y 6?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar