-
Notifications
You must be signed in to change notification settings - Fork 0
/
ver_tablero.c
79 lines (71 loc) · 1.94 KB
/
ver_tablero.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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "strutil.h"
#include "constantes.c"
#include "cola.h"
bool ver_tablero(char* parametros[], aerolinea_t* vuelos){
int n = atoi(parametros[0]);
char* modo = parametros[1];
char** vector_clavei = calloc(3, sizeof(char*));
vector_clavei[0] = parametros[2];
vector_clavei[1] = "0000";
char* clave_inicial = join(vector_clavei, '_');
char** vector_clavef = calloc(3,sizeof(char*));
vector_clavef[0] = parametros[3];
vector_clavef[1] = "9999";
char* clave_final = join(vector_clavef, '_');
abb_iter_t* iter = abb_iter_in_crear(vuelos->abb, clave_inicial);
char* clave = abb_iter_in_ver_actual(iter);
if (abb_iter_in_al_final(iter)) {
abb_iter_in_destruir(iter);
return true;
}
if(strcmp(modo, "asc") == 0){
cola_t* cola = cola_crear();
bool seguir = true;
while (seguir && strcmp(clave_final, clave) > 0){
cola_encolar(cola,clave);
abb_iter_in_avanzar(iter);
clave = abb_iter_in_ver_actual(iter);
if (clave == NULL) seguir = false;
}
int i = 0;
while (!cola_esta_vacia(cola) && (i < n)){
char** clave = split(cola_desencolar(cola), '_');
printf("%s",clave[0]);
printf("%s"," - ");
printf("%s\n",clave[1]);
free_strv(clave);
i++;
}
cola_destruir(cola,NULL);
}
if(strcmp(modo, "desc") == 0){
pila_t* pila = pila_crear();
bool seguir = true;
while (seguir && strcmp(clave_final, clave) > 0){
pila_apilar(pila,clave);
abb_iter_in_avanzar(iter);
clave = abb_iter_in_ver_actual(iter);
if (clave == NULL) seguir = false;
}
int i = 0;
while (!pila_esta_vacia(pila) && (i < n)){
char** clave = split(pila_desapilar(pila), '_');
printf("%s",clave[0]);
printf("%s"," - ");
printf("%s\n",clave[1]);
free_strv(clave);
i++;
}
pila_destruir(pila);
}
abb_iter_in_destruir(iter);
free(vector_clavef);
free(clave_final);
free(clave_inicial);
free(vector_clavei);
return true;
}