-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pilas.c
135 lines (103 loc) · 2.35 KB
/
Pilas.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void MostrarMenu();
void MostrarPila ();
void AgregarElementosPila ();
void RemoverElementoPila();
struct PILA
{
int noserie;
struct PILA *next;
};
struct PILA *producto = NULL;
int main () {
MostrarMenu();
return 0;
}
void MostrarMenu()
{
int opc;
do
{
printf("\n------------CONTROL DE STOCK---------\n");
printf("\n1. Mostrar STOCK\n");
printf("2. Agregar unidades\n");
printf("3. Remover unidad\n");
printf("4. Salir");
printf("\n\nInserte su opcion: ");
scanf("%d", &opc);
} while (opc < 1 || opc > 4);
switch (opc)
{
case 1:
MostrarPila();
break;
case 2:
AgregarElementosPila();
break;
case 3:
RemoverElementoPila();
break;
default:
break;
}
}
void AgregarElementosPila () {
srand(time(NULL));
int cantidad;
printf ("\nCuantos elementos desea: ");
scanf ("%d", &cantidad);
for (size_t i = 0; i < cantidad; i++)
{
struct PILA *unidad = malloc (1 * sizeof(struct PILA));
int num = (rand() % (1000 - 1 + 1)) + 1; //(max - min +1) + min
unidad->noserie = num;
if (producto == NULL) {
producto = unidad;
unidad->next = NULL;
}
else {
unidad->next = producto;
producto = unidad;
}
unidad = NULL;
free (unidad);
}
MostrarMenu ();
}
void MostrarPila () {
printf ("\nProductos en STOCK\n\n");
struct PILA *aux;
aux = producto;
if (aux == NULL) {
printf ("No hay stock\n");
MostrarMenu();
}
int cantidad = 1;
while (aux) {
printf ("%d. Numero de serie: %d\n", cantidad, aux->noserie);
aux = aux->next;
cantidad++;
}
MostrarMenu();
}
void RemoverElementoPila() {
int cantidad;
printf ("\nCuantos prodcutos deseas remover de STOCK ?: ");
scanf ("%d", &cantidad);
struct PILA *aux = producto;
for (size_t i = 0; i < cantidad; i++)
{
if (aux = NULL) {
printf ("\nEl stock esta vacio\n");
MostrarMenu ();
}
else {
producto = producto->next;
free (aux);
aux = producto;
}
}
MostrarMenu ();
}