Last active
October 27, 2021 17:11
-
-
Save joaquinvelez23/37fe8dcf61eda9256f168db136338286 to your computer and use it in GitHub Desktop.
Un conductor maneja de un pueblo origen a un pueblo destino, se muestran el recorrido de ida y vuelta con pilas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** CREADO POR JOAQUIN VELEZ 27/10/21 **/ | |
| #include <iostream> | |
| #include <string> | |
| #include <stdlib.h> | |
| using namespace std; | |
| #define MAX 50 | |
| struct Nodo{ | |
| string pueblo; | |
| struct Nodo *siguiente; | |
| }; | |
| void crearNodo (Nodo *&pila, string dato[MAX], int n); | |
| void mostarPila (Nodo *pila); | |
| int main(){ | |
| Nodo *pila=NULL; | |
| int n; //cantidad de pueblos recorridos | |
| string recorrido[MAX]; | |
| cout << "Digite cantidad de pueblos de COMIENZO a DESTINO: "; | |
| cin >> n; | |
| system("pause"); | |
| system("cls"); | |
| cin.ignore(); | |
| for (int i=0; i<n; i++){ | |
| cout << "---CARGA DE RECORRIDO---" << endl; | |
| cout << "Digite pueblo (" << i+1 << "): "; | |
| getline(cin, recorrido[i]); | |
| system("pause"); | |
| system("cls"); | |
| } | |
| crearNodo(pila, recorrido, n); | |
| cout << "---RECORRIDO DE IDA---" << endl; | |
| for (int i=0; i<n; i++){ | |
| cout << "Pueblo (" << i+1 << "): "; | |
| cout << recorrido[i] << endl; | |
| } | |
| cout << "\n"; | |
| mostarPila(pila); | |
| return 0; | |
| } | |
| void crearNodo (Nodo *&pila, string dato[MAX], int n){ | |
| for(int i=0; i<n; i++){ | |
| Nodo *nuevo_nodo = new (struct Nodo); | |
| nuevo_nodo ->siguiente = pila; | |
| nuevo_nodo ->pueblo = dato[i]; | |
| pila = nuevo_nodo; | |
| } | |
| } | |
| void mostarPila (Nodo *pila){ | |
| int index = 1; | |
| Nodo *aux; | |
| aux = pila; | |
| cout << "---RECORRIDO VUELTA---" << endl; | |
| while (aux != NULL){ | |
| cout << "Pueblo (" << index << "): "; | |
| cout << aux ->pueblo << endl; | |
| aux = aux->siguiente; | |
| index++; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment