Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Andrés Partida Álvarez
- Nombre De la practica: "Pila Dinamica"
- Fecha: 18/11/11
- Sección: D04
- */
- # include <stdio.h>
- # include <stdlib.h>
- # include "Funciones_7_pil_din.h"
- int main()
- {
- char resp;
- int dato;
- Pila *P;
- inicializar(P);
- do
- {
- system("cls");
- printf("\t\t*** Pilas Dinamicas Basadas en LSLLSE ***\n");
- printf("\t\t\t*** MENU ***\nA).- Apilar\nD).- Desapilar\nI).- Inicializar(anular)\nM).- Mostrar\nT).- Tope\nS).- salir\n>>> ");
- fflush(stdin);
- scanf("%c",&resp);
- resp = toupper(resp);
- switch (resp)
- {
- case 'A': //system("cls");
- printf("Escriba el numero a APILAR\n");
- scanf("%i",&dato);
- apilar(&dato, P);
- printf("Dato apilado\n");
- break;
- case 'D': //system("cls");
- if (vacia(P))
- printf("La Pila esta vacia\n");
- else
- {
- desapilar(P);
- printf("Elemento desapilado\n");
- }
- break;
- case 'I': //system("cls");
- inicializar(P);
- printf("La pila ha sido inicializada\n");
- break;
- case 'M': //system("cls");
- if(vacia(P))
- {
- printf("\t\t*** LISTA VACIA ***\n");
- }
- else
- printf("Elementos apilados...\n");
- mostrarPila(P);
- break;
- /*case 'T':
- if (vacia(P))
- printf("La pila esta vacia\n");
- else
- printf("Elemento del tope es:\n");
- printf("%i",tope(&P)->elem);
- break;*/
- case 'S': printf("\t\t*** FIN DEL PROGRAMA ***\a\a\n");
- break;
- default : printf("\t\tOpcion No valida\a\a\n");
- break;
- }
- system("pause");
- }while (resp != 'S');
- return 0;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- #ifndef FUNCIONES_7_PIL_DIN_H_INCLUDED
- #define FUNCIONES_7_PIL_DIN_H_INCLUDED
- typedef struct Nodo
- {
- int elem;
- struct Nodo *sig;
- }Nodo;
- typedef Nodo *pos;
- typedef Nodo *Pila;
- void inicializar(Pila *P)
- {
- *P = NULL;
- }
- pos recevaNodo()
- {
- Nodo * aux;
- aux = (Nodo*)malloc(sizeof(Nodo));
- return aux;
- }
- int vacia(Pila *P)
- {
- if (*P == NULL)
- return 1;
- else
- return 0;
- }
- void apilar(int *x, Pila *P)
- {
- pos aux;
- aux = recevaNodo();
- if (aux)
- {
- aux->elem = *x;
- aux->sig = *P;
- *P = aux;
- }
- }
- void desapilar(Pila *P)
- {
- Nodo *aux;
- aux = *P;
- *P= aux->sig;
- free(aux);
- }
- void mostrarPila(Pila *P)
- {
- Nodo *aux;
- aux = *P;
- while (aux != NULL )
- {
- printf("%i\n",aux->elem);
- aux = aux->sig;
- }
- }
- /*pos tope(Pila *P)
- {
- pos aux;
- aux = *P;
- if (!vacia(P))
- {
- while (aux != NULL)
- aux = aux->sig;
- return &aux;
- }
- else
- return 0;
- }*/
- #endif // FUNCIONES_7_PIL_DIN_H_INCLUDED
Add Comment
Please, Sign In to add comment