Pascal/Turbo Pascal - ayuda con arboles y file

 
Vista:

ayuda con arboles y file

Publicado por juan (2 intervenciones) el 30/11/2012 20:39:22
bueno resulta que necesito un procedure en el cual logre insertar un arbol binario manteniendo su estructura a un archivo file y luego poder usar este arbol con su estructura posteriormente.
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

ayuda con arboles y file

Publicado por ramon (2158 intervenciones) el 30/11/2012 21:06:09
Puedes pasar la estructura del registro y las variables para mejor informarte.
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

ayuda con arboles y file

Publicado por juan (2 intervenciones) el 02/12/2012 03:07:51
1
2
3
4
5
6
7
type str20       = string[20];
      tipo.punt = ^tipo.nodo;
      tipo.nodo    = record
                      texto : str20;
                      si    : tipo.punt;
                      no    : tipo.punt;
                     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

ayuda con arboles y file

Publicado por ramon (2158 intervenciones) el 05/12/2012 16:57:08
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
173
174
175
176
177
178
179
180
181
182
183
{A ver mira esto a ver si vale}
 
Program arbol;
uses crt;
const
    nombre = 'c:\tp\datonodo.dat';
 
type
      str20 = string[20];
      punt = ^nodo;
      nodo = record
                 texto : str20;
                 si    : punt;
                 no    : punt;
                End;
 
   var
     inic : punt;
      da1 : nodo;
    datos : str20;
    acion : char;
    f : file of nodo;
    i, cont : longint;
 
    procedure guardadatos(da : nodo);
    begin
       assign(f,nombre);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
        rewrite(f);
        seek(f,0);
        write(f,da);
        close(f);
    end
  else
     begin
        seek(f,filesize(f));
        write(f,da);
        close(f);
     end;
    end;
 
    procedure iniciararbol;
    begin
        inic := nil;
    end;
 
   procedure insertarenarbol(d : str20; var inic : punt; cu : integer);
   begin
     if inic = nil then
     begin
          new(inic);
          with inic^ do
          begin
               texto := d;
               si := nil;
               no := nil;
               if cu = 0 then
               guardadatos(inic^);
          end;
      end
     else
        begin
       if  d < inic^.texto then
       insertarenarbol(d, inic^.si,cu)
     else
       insertarenarbol(d, inic^.no,cu);
       end;
     end;
 
    procedure enpreorden(inic : punt);
    begin
     if inic <> nil then
       begin
         writeln(inic^.texto);
         enpreorden(inic^.si);
         enpreorden(inic^.no);
      end;
    end;
 
    procedure eninorden(inic : punt);
    begin
      if inic <> nil then
      begin
         eninorden(inic^.si);
         Writeln(inic^.texto);
         eninorden(inic^.no);
      end;
    end;
 
   procedure enpostorden(inic : punt);
   begin
      if inic <> nil then
      begin
         enpostorden(inic^.si);
         enpostorden(inic^.no);
         writeln(inic^.texto);
       end;
    end;
 
   procedure cargadatos;
    var
      t : longint;
    begin
       assign(f,nombre);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
      clrscr;
      writeln('   Error De Archivo Pulse [Enter]');
      readln;
      exit;
     end
   else
       begin
          for t := 0 to filesize(f) - 1 do
          begin
              seek(f,t);
              read(f,da1);
              insertarenarbol(da1.texto,inic,1);
          end;
           close(f);
       end;
    end;
 
 
   procedure introducirdatos;
   var
     dd : str20;
     j : integer;
   begin
       clrscr;
       repeat
              writeln('**** Entrada datos ****');
              writeln;
              begin
                 write('  Entre : ');
                 readln(dd);
                 insertarenarbol(dd,inic,0);
                 writeln(' Desea Insertar Mas Datos [S/N] : ');
              end;
               repeat
               acion := upcase(readkey);
               until acion in['S','N'];
        until acion = 'N';
        clrscr;
    end;
 
    begin
     clrscr;
       cont := 0;
       iniciararbol;
     repeat
         clrscr;
         gotoxy (3,1); write('Men£ de Opciones');
         gotoxy(3,2);write(' 1 = Introducir Datos');
         gotoxy(3,3);write(' 2 = Visualizar en Preorden');
         gotoxy(3,4);write(' 3 = Visualizar en Inorden');
         gotoxy(3,5);write(' 4 = Visualizar en Postorden');
         gotoxy(3,6);write(' 5 = Cargar Datos De Archivo');
         gotoxy(3,7);write(' 6 = Fin del programa');
         gotoxy(3,9);write('***** Elije opci¢n *****');
         repeat
         acion := readkey;
         until acion in['1','2','3','4','5','6'];
         case acion of
              '1': begin clrscr; introducirdatos;  end;
              '2': begin clrscr; enpreorden(inic); readln; end;
              '3': begin clrscr; enpostorden(inic); readln; end;
              '4': begin clrscr; eninorden(inic); readln; end;
              '5': begin
                    clrscr;
                      iniciararbol;
                      writeln('  Cargados Datos ');
                      cargadatos;
                      writeln(' Fin Carga Pulsa [Enter]');
                      readln;
                    end;
              end;
     until acion = '6';
 
   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