
insertar ordenado en una lista.
Publicado por Diego (98 intervenciones) el 18/10/2013 22:49:10
Buenas tardes, no veo claramente cual es el problema que tengo al crear dos listas ordenanas por un criterio. hice dos lista que insertan ordenadamente, pero parece que solo inserta si los criterios para la inserción van de mayor a menor, al intentar cargar datos en otro orden me da error.
Utilizo el Dev-Pascal
Utilizo el Dev-Pascal
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
program ejercicio5;
type
info_productos = record
cod_pro : integer;
nom_pro : string;
stock_actual : integer;
stock_minimo : integer;
precio_unitario : real;
end;
lista_productos = ^nodo_pro;
nodo_pro = record
elemen_pro : info_productos;
dirSig_pro : lista_productos;
end;
info_ventas = record
num_venta : integer;
cod_pro: integer;
cant_vendida : integer;
end;
lista_ventas = ^nodo_vent;
nodo_vent = record
elemen_vent : info_ventas;
dirSig_vent : lista_ventas;
end;
info_arbol = record
cod_pro : integer;
stock_a_reponer : integer;
end;
T_arbol = ^nodo_arbol;
nodo_arbol = record
hijo_der : T_arbol;
elemen_arbol : info_arbol;
hijo_izq : T_arbol;
end;
procedure crear_lista_pro (var L : lista_productos);
begin
L:= nil;
end;
procedure crear_lista_vent(var L : lista_ventas);
begin
L := nil;
end;
procedure crear_arbol(var a: T_arbol);
begin
a:= nil;
end;
procedure leer_info_pro(var reg_pro : info_productos);
begin
with (reg_pro) do
begin
write('Ingrese el código del producto: ');
readln(cod_pro);
if (cod_pro <> -1) then
begin
write('Ingrese el nombre del producto: ');
readln(nom_pro);
write('Ingrese el stock actual del producto: ');
readln(stock_actual);
write('Ingrese el stock minimo producto: ');
readln(stock_minimo);
write('Ingrese el precio unitario del producto: ');
readln(precio_unitario);
end;
end;
end;
procedure insertar_ord_pro(var list_pro : lista_productos; reg_pro: info_productos);
var
nue: lista_productos;
ant, act : lista_productos;
begin
new(nue);
nue^.elemen_pro := reg_pro;
nue^.dirSig_pro := nil;
if (reg_pro.cod_pro < list_pro^.elemen_pro.cod_pro) then
begin
nue^.dirSig_pro := list_pro;
list_pro := nue;
end
else
begin
act := list_pro;
ant := act;
while ((act <> nil) and (reg_pro.cod_pro > act^.elemen_pro.cod_pro)) do
begin
ant := act;
act := act^.dirSig_pro;
end;
if (reg_pro.cod_pro < act^.elemen_pro.cod_pro) then
nue^.dirSig_pro := ant^.dirSig_pro;
ant^.dirSig_pro := nue;
end;
end;
procedure cargar_lista_productos(var list_pro : lista_productos);
var
reg_pro : info_productos;
begin
leer_info_pro(reg_pro);
if (reg_pro.cod_pro <> -1) then
begin
new(list_pro);
list_pro^.elemen_pro := reg_pro;
list_pro^.dirSig_pro := nil;
leer_info_pro(reg_pro);
while (reg_pro.cod_pro <> -1) do
begin
insertar_ord_pro(list_pro, reg_pro);
leer_info_pro(reg_pro);
end;
end;
end;
procedure leer_info_vent(var reg_vent: info_ventas);
begin
with (reg_vent) do
begin
write('Ingrese el código del producto: ');
readln(cod_pro);
if (cod_pro <> -1) then
begin
write('Ingrese el número de venta: ');
readln(num_venta);
write('Ingrese la cantidad vendida: ');
readln(cant_vendida);
end;
end;
end;
procedure insertar_ord_vent(var list_vent: lista_ventas; reg_vent: info_ventas);
var
nue: lista_ventas;
ant, act : lista_ventas;
begin
new(nue);
nue^.elemen_vent := reg_vent;
nue^.dirSig_vent := nil;
if (reg_vent.cod_pro < list_vent^.elemen_vent.cod_pro) then
begin
nue^.dirSig_vent := list_vent;
list_vent := nue;
end
else
begin
act := list_vent;
ant := act;
while (act <> nil) and (reg_vent.cod_pro > act^.elemen_vent.cod_pro) do
begin
ant := act;
act:= act^.dirSig_vent;
end;
if (reg_vent.cod_pro < act^.elemen_vent.cod_pro) then
nue^.dirSig_vent := ant^.dirSig_vent;
ant^.dirSig_vent := nue;
end;
end;
procedure cargar_lista_ventas(var list_vent: lista_ventas);
var
reg_vent : info_ventas;
begin
leer_info_vent(reg_vent);
if (reg_vent.cod_pro <> -1) then
begin
new(list_vent);
list_vent^.elemen_vent := reg_vent;
list_vent^.dirSig_vent := nil;
leer_info_vent(reg_vent);
while (reg_vent.cod_pro <> -1) do
begin
insertar_ord_vent(list_vent, reg_vent);
leer_info_vent(reg_vent);
end;
end;
end;
procedure imprimir_lista_productos(L : lista_productos);
begin
while (L <> nil) do
begin
writeln('Código del producto: ', L^.elemen_pro.cod_pro);
writeln('Nombre del producto: ', L^.elemen_pro.nom_pro);
writeln('Stock actual del producto: ', L^.elemen_pro.stock_actual);
writeln('Stock minimo del producto: ', L^.elemen_pro.stock_minimo);
writeln('Precio unitario del producto: ', L^.elemen_pro.precio_unitario);
writeln();
L := L^.dirSig_pro;
end;
end;
procedure imprimir_lista_ventas(L : lista_ventas);
begin
while (L <> nil) do
begin
writeln('Código del producto: ', L^.elemen_vent.cod_pro);
writeln('Número de venta del producto: ', L^.elemen_vent.num_venta);
writeln('Cantidad vendida del producto: ', L^.elemen_vent.cant_vendida);
writeln();
L := L^.dirSig_vent;
end;
end;
var
list_pro : lista_productos;
list_vent : lista_ventas;
begin
crear_lista_pro(list_pro);
crear_lista_vent(list_vent);
writeln('---------------Lista de Productos--------------');
cargar_lista_productos(list_pro);
writeln('------------------------X----------------------');
writeln('---------------Lista de Ventas--------------');
cargar_lista_ventas(list_vent);
writeln('------------------------X----------------------');
writeln('---------------Lista de Productos--------------');
imprimir_lista_productos(list_pro);
writeln('------------------------X----------------------');
writeln('---------------Lista de Ventas--------------');
imprimir_lista_ventas(list_vent);
writeln('------------------------X----------------------');
readln();
readln();
end.
Valora esta pregunta


0