Last active
March 3, 2016 22:15
Revisions
-
martincruz-bx revised this gist
Jul 26, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ * C++ - Pilas/Stack * Copyright 2014 Martin Cruz Otiniano * Description : Apila elemento, Desempila elemento, Mostrar pila, Destruir Pila * Site : martincruz.me */ #include <iostream> -
martincruz-bx revised this gist
Nov 22, 2014 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,8 @@ /* * C++ - Pilas/Stack * Copyright 2014 Martin Cruz Otiniano * Description : Apila elemento, Desempila elemento, Mostrar pila, Destruir Pila * Site : www.marcsdev.com */ #include <iostream> -
martincruz-bx revised this gist
Oct 4, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ * Description: Apila elemento, Desempila elemento, Mostrar pila, Destruir Pila * Site: casicodigo.blogspot.com */ #include <iostream> using namespace std; -
martincruz-bx revised this gist
Oct 4, 2014 . 1 changed file with 33 additions and 33 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ */ #include <iostream> using namespace std; struct nodo{ @@ -18,77 +18,77 @@ struct nodo{ typedef nodo *ptrPila; // creando nodo tipo puntero( tipo de dato ) /* Apilar elemento ------------------------------------------------------------------------*/ void push( ptrPila &p, int valor ) { ptrPila aux; aux = new(struct nodo); // apuntamos al nuevo nodo creado aux->nro = valor; aux->sgte = p ; p = aux ; } /* Desapilar elemento(devuelve elemento) ------------------------------------------------------------------------*/ int pop( ptrPila &p ) { int num ; ptrPila aux; aux = p ; num = aux->nro; // asignamos el primer vamor de la pila p = aux->sgte ; delete(aux); return num; } /* Muestra elementos de la pila ------------------------------------------------------------------------*/ void mostrar_pila( ptrPila p ) { ptrPila aux; aux = p; // apunta al inicio de la lista while( aux !=NULL ) { cout<<"\t"<< aux->nro <<endl; aux = aux->sgte; } } /* Eliminar todos los elementos de la pila ------------------------------------------------------------------------*/ void destruir_pila( ptrPila &p) { ptrPila aux; while( p != NULL) { aux = p; p = aux->sgte; delete(aux); } } /* Menu de opciones ------------------------------------------------------------------------*/ void menu() { cout<<"\n\t IMPLEMENTACION DE PILAS EN C++\n\n"; cout<<" 1. APILAR "<<endl; cout<<" 2. DESAPILAR "<<endl; cout<<" 3. MOSTRAR PILA "<<endl; cout<<" 4. DESTRUIR PILA "<<endl; cout<<" 5. SALIR "<<endl; cout<<"\n INGRESE OPCION: "; } /* Funcion Principal ------------------------------------------------------------------------*/ int main() { ptrPila p = NULL; // creando pila @@ -100,44 +100,44 @@ int main() do { menu(); cin>> op; switch(op) { case 1: cout<< "\n NUMERO A APILAR: "; cin>> dato; push( p, dato ); cout<<"\n\n\t\tNumero " << dato << " apilado...\n\n"; break; case 2: x = pop( p ); cout<<"\n\n\t\tNumero "<< x <<" desapilado...\n\n"; break; case 3: cout << "\n\n MOSTRANDO PILA\n\n"; if(p!=NULL) mostrar_pila( p ); else cout<<"\n\n\tPila vacia..!"<<endl; break; case 4: destruir_pila( p ); cout<<"\n\n\t\tPila eliminada...\n\n"; break; } cout<<endl<<endl; system("pause"); system("cls"); }while(op!=5); -
martincruz-bx created this gist
Oct 4, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,147 @@ /* * C++ - Pilas/Stack * Copyright 2014 Martin Cruz Otiniano <slayer.dmx@gmail.com> * * Description: Apila elemento, Desempila elemento, Mostrar pila, Destruir Pila * Site: casicodigo.blogspot.com */ #include <iostream> using namespace std; struct nodo{ int nro; struct nodo *sgte; }; typedef nodo *ptrPila; // creando nodo tipo puntero( tipo de dato ) /* Apilar elemento ---------------------------------------------------------------------*/ void push( ptrPila &p, int valor ) { ptrPila aux; aux = new(struct nodo); // apuntamos al nuevo nodo creado aux->nro = valor; aux->sgte = p ; p = aux ; } /* Desapilar elemento(devuelve elemento) ---------------------------------------------------------------------*/ int pop( ptrPila &p ) { int num ; ptrPila aux; aux = p ; num = aux->nro; // asignamos el primer vamor de la pila p = aux->sgte ; delete(aux); return num; } /* Muestra elementos de la pila ---------------------------------------------------------------------*/ void mostrar_pila( ptrPila p ) { ptrPila aux; aux = p; // apunta al inicio de la lista while( aux !=NULL ) { cout<<"\t"<< aux->nro <<endl; aux = aux->sgte; } } /* Eliminar todos los elementos de la pila ---------------------------------------------------------------------*/ void destruir_pila( ptrPila &p) { ptrPila aux; while( p != NULL) { aux = p; p = aux->sgte; delete(aux); } } /* Menu de opciones ----------------------------------------------------------------------*/ void menu() { cout<<"\n\t IMPLEMENTACION DE PILAS EN C++\n\n"; cout<<" 1. APILAR "<<endl; cout<<" 2. DESAPILAR "<<endl; cout<<" 3. MOSTRAR PILA "<<endl; cout<<" 4. DESTRUIR PILA "<<endl; cout<<" 5. SALIR "<<endl; cout<<"\n INGRESE OPCION: "; } /* Funcion Principal ----------------------------------------------------------------------*/ int main() { ptrPila p = NULL; // creando pila int dato; int op; int x ; // numero que devuelve la funcon pop system("color 0b"); do { menu(); cin>> op; switch(op) { case 1: cout<< "\n NUMERO A APILAR: "; cin>> dato; push( p, dato ); cout<<"\n\n\t\tNumero " << dato << " apilado...\n\n"; break; case 2: x = pop( p ); cout<<"\n\n\t\tNumero "<< x <<" desapilado...\n\n"; break; case 3: cout << "\n\n MOSTRANDO PILA\n\n"; if(p!=NULL) mostrar_pila( p ); else cout<<"\n\n\tPila vacia..!"<<endl; break; case 4: destruir_pila( p ); cout<<"\n\n\t\tPila eliminada...\n\n"; break; } cout<<endl<<endl; system("pause"); system("cls"); }while(op!=5); return 0; }