-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colas.c
112 lines (87 loc) · 1.86 KB
/
Colas.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
#include <stdio.h>
#include <stdlib.h>
void MostrarMenu ();
void MostrarCola();
void AgregarElementoCola();
void RemoverElementoCola();
struct COLA
{
char nombre[50];
struct COLA *prev;
};
struct COLA *CuentaCobro = NULL;
int main()
{
MostrarMenu();
return 0;
}
void MostrarMenu()
{
int opc;
do
{
printf("\n------------CONTROL DE COLA---------\n");
printf("\n1. Mostrar Cola\n");
printf("2. Agregar cliente a la cola\n");
printf("3. Remover cliente atendido\n");
printf("4. Salir");
printf("\n\nInserte su opcion: ");
scanf("%d", &opc);
} while (opc < 1 || opc > 4);
switch (opc)
{
case 1:
MostrarCola();
break;
case 2:
AgregarElementoCola();
break;
case 3:
RemoverElementoCola();
break;
default:
break;
}
}
void MostrarCola()
{
printf("\nCLIENTES EN LA COLA:\n\n");
struct COLA *aux = CuentaCobro;
for (int i = 1; aux; i++)
{
printf("Posicion: %d\t Nombre: %s\n", i, aux->nombre);
aux = aux->prev;
}
MostrarMenu();
}
void AgregarElementoCola()
{
struct COLA cliente;
printf("Escriba el nombre del nuevo cliente: ");
scanf("%s", &cliente.nombre);
cliente.prev = NULL;
if (CuentaCobro == NULL)
CuentaCobro = &cliente;
else
{
struct COLA *aux = CuentaCobro;
while (aux->prev != NULL)
aux = aux->prev;
aux->prev = &cliente;
}
MostrarMenu();
}
void RemoverElementoCola()
{
if (CuentaCobro)
{
printf("El cliente %s ha sido atendido", CuentaCobro->nombre);
struct COLA *aux = malloc(1 * sizeof(struct COLA));
aux = CuentaCobro;
CuentaCobro = CuentaCobro->prev;
aux->prev = NULL;
aux = NULL;
free(aux);
}
MostrarMenu();
}