|
| 1 | +#include <iostream> |
| 2 | +#include <iomanip> |
| 3 | +#include <fstream> |
| 4 | +#include <stdlib.h> |
| 5 | +using namespace std; |
| 6 | +struct T1{ |
| 7 | + int N; |
| 8 | + string exp, grupo, nombre; |
| 9 | +}; |
| 10 | +typedef T1 _T1; |
| 11 | +struct nodo{ |
| 12 | + _T1 info; |
| 13 | + nodo* sig; |
| 14 | +}; |
| 15 | +typedef nodo* ptnodo; |
| 16 | +ptnodo pila1, pila2; |
| 17 | +// funciones |
| 18 | +void push(ptnodo &pila, T1 &elem); |
| 19 | +void cima(ptnodo &pila,string &elem); |
| 20 | +void pop(ptnodo &pila, T1 &elem); |
| 21 | +void mostrar(T1 *ptregistro); |
| 22 | +void borrar_pila(ptnodo &pila); |
| 23 | +int main() { |
| 24 | + string elem, cim; |
| 25 | + int opc, i = 0; |
| 26 | + ifstream A1; |
| 27 | + T1 registro, *ptregistro = NULL; |
| 28 | + while(opc != 6){ |
| 29 | + cout << "Menu de opciones\n"; |
| 30 | + cout << "1.- Cargar datos\n"; |
| 31 | + cout << "2.- Mostrar los datos cargados\n"; |
| 32 | + cout << "3.- Ordenar datos por expedientes\n"; |
| 33 | + cout << "4.- Cargar datos en una pila\n"; |
| 34 | + cout << "5.- Opcion adicional\n"; |
| 35 | + cout << "6.- Salir\n"; |
| 36 | + cin >> opc; |
| 37 | + system("cls"); |
| 38 | + switch(opc){ |
| 39 | + case 1: |
| 40 | + if(ptregistro != NULL){// liberar memoria |
| 41 | + delete[] ptregistro; |
| 42 | + borrar_pila(pila1); |
| 43 | + borrar_pila(pila2); |
| 44 | + } |
| 45 | + ptregistro = new T1[27]; |
| 46 | + A1.open("lista3.txt"); |
| 47 | + if(!A1){ |
| 48 | + cout << "Error al abrir archivo"; |
| 49 | + } |
| 50 | + A1>> ptregistro -> N; |
| 51 | + A1.ignore(1); |
| 52 | + getline(A1,ptregistro -> exp,'\t'); |
| 53 | + getline(A1,ptregistro -> grupo,'\t'); |
| 54 | + getline(A1,ptregistro -> nombre); |
| 55 | + i = 1; |
| 56 | + while(A1.eof() == 0){ |
| 57 | + A1>>ptregistro[i].N; |
| 58 | + A1.ignore(1); |
| 59 | + getline(A1,ptregistro[i].exp,'\t'); |
| 60 | + getline(A1,ptregistro[i].grupo,'\t'); |
| 61 | + getline(A1,ptregistro[i].nombre); |
| 62 | + i++; |
| 63 | + } |
| 64 | + A1.close(); |
| 65 | + break; |
| 66 | + case 2: |
| 67 | + mostrar(ptregistro); |
| 68 | + break; |
| 69 | + case 3: |
| 70 | + if(pila1 != NULL) |
| 71 | + borrar_pila(pila1); |
| 72 | + push(pila1, ptregistro[0]); |
| 73 | + i = 1; |
| 74 | + while (i < 27){ |
| 75 | + elem = ptregistro[i].exp; |
| 76 | + cima(pila1, cim); |
| 77 | + while(pila1 !=NULL && cim < elem){ |
| 78 | + pop(pila1, registro); |
| 79 | + push(pila2, registro); |
| 80 | + cima(pila1, cim); |
| 81 | + } |
| 82 | + push(pila1, ptregistro[i]); |
| 83 | + while(pila2 != NULL){ |
| 84 | + pop(pila2, registro); |
| 85 | + push(pila1, registro); |
| 86 | + } |
| 87 | + i++; |
| 88 | + } |
| 89 | + i = 0; |
| 90 | + while(pila1 != NULL){ |
| 91 | + pop(pila1, ptregistro[i]); |
| 92 | + i++; |
| 93 | + } |
| 94 | + mostrar(ptregistro); |
| 95 | + break; |
| 96 | + case 4: |
| 97 | + if(pila1 != NULL) |
| 98 | + borrar_pila(pila1); |
| 99 | + for(i = 26; i >= 0; i--) |
| 100 | + push(pila1, ptregistro[i]); |
| 101 | + cout << "se muestran los datos almacenados en la pila\n\n"; |
| 102 | + mostrar(ptregistro); |
| 103 | + break; |
| 104 | + |
| 105 | + case 5: |
| 106 | + if(pila1 != NULL) |
| 107 | + borrar_pila(pila1); |
| 108 | + if(pila2 != NULL) |
| 109 | + borrar_pila(pila2); |
| 110 | + i = 26; |
| 111 | + while (i >= 0){ |
| 112 | + elem = ptregistro[i].grupo; |
| 113 | + if(elem == "G2") |
| 114 | + push(pila1, ptregistro[i]); |
| 115 | + cima(pila1, cim); |
| 116 | + i--; |
| 117 | + } |
| 118 | + i = 0; |
| 119 | + while (i < 27) { |
| 120 | + elem = ptregistro[i].grupo; |
| 121 | + if(elem == "G1") |
| 122 | + push(pila2, ptregistro[i]); |
| 123 | + cima(pila2, cim); |
| 124 | + i++; |
| 125 | + } |
| 126 | + while(pila2 != NULL){ |
| 127 | + pop(pila2, registro); |
| 128 | + push(pila1, registro); |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | + i = 0; |
| 133 | + while(pila1 != NULL){ |
| 134 | + pop(pila1, ptregistro[i]); |
| 135 | + i++; |
| 136 | + } |
| 137 | + mostrar(ptregistro); |
| 138 | + break; |
| 139 | + case 6: |
| 140 | + // liberar memoria |
| 141 | + delete[] ptregistro; |
| 142 | + borrar_pila(pila1); |
| 143 | + borrar_pila(pila2); |
| 144 | + break; |
| 145 | + default: |
| 146 | + cout << "Ingrese una opcion valida \n\n"; |
| 147 | + break; |
| 148 | + } |
| 149 | + } |
| 150 | + return 0; |
| 151 | + } |
| 152 | +void push(ptnodo &pila,T1 &elem){ |
| 153 | + ptnodo nuevo; |
| 154 | + nuevo = new(nodo); |
| 155 | + nuevo -> info = elem; |
| 156 | + nuevo -> sig = NULL; |
| 157 | + if(pila == NULL) |
| 158 | + pila = nuevo; |
| 159 | + else{ |
| 160 | + nuevo -> sig = pila; |
| 161 | + pila = nuevo; |
| 162 | + } |
| 163 | +} |
| 164 | +void cima(ptnodo &pila,string &elem){ |
| 165 | + if(pila != NULL) |
| 166 | + elem = pila -> info.exp; |
| 167 | +} |
| 168 | +void pop(ptnodo &pila, T1 &elem){ |
| 169 | + ptnodo Aux = pila; |
| 170 | + if(Aux != NULL){ |
| 171 | + pila = pila -> sig; |
| 172 | + elem = Aux -> info; |
| 173 | + delete(Aux); |
| 174 | + }else{ |
| 175 | + cout << "error popa" << endl;} |
| 176 | +} |
| 177 | +void mostrar(T1 *ptregistro){ |
| 178 | + for(int i = 0; i < 27; i++){ |
| 179 | + cout << setw(3) << left <<ptregistro[i].N; |
| 180 | + cout << setw(13) << ptregistro[i].exp; |
| 181 | + cout << setw(4) << ptregistro[i].grupo; |
| 182 | + cout << setw(24) << ptregistro[i].nombre <<endl; |
| 183 | + } |
| 184 | +} |
| 185 | +void borrar_pila(ptnodo &pila){ |
| 186 | + T1 elem; |
| 187 | + while(pila != NULL) |
| 188 | + pop(pila, elem); |
| 189 | + } |
0 commit comments