Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define TAMMAX 10
- typedef struct PilaEstatica
- {
- int tope;
- int elementos[TAMMAX];
- }pila;
- pila Pila;
- //Para inicializar la pila
- void Initialize(pila *p)
- {
- p->tope=0;
- }
- int IsEmpty(pila *p)
- {
- if((p->tope)==0)
- return 1;
- else
- return 0;
- }
- int IsFull(pila *p)
- {
- if((p->tope)==TAMMAX)
- return 1;
- else
- return 0;
- }
- int Push(pila *p, int dato)
- {
- if(IsFull(p))
- return 1;
- p->elementos[p->tope]=dato;
- p->tope++;
- return 1;
- }
- int Pop(pila *p, int dato)
- {
- if(IsEmpty(p))
- return 0;
- else
- dato=p->elementos[p->tope-1];
- p->tope--;
- }
- int Purge(pila *p)
- {
- int cont;
- if(IsEmpty(p))
- return 0;
- else
- for(cont=0;cont<=TAMMAX;cont++)
- {
- p->elementos[cont]=0;
- p->tope--;
- }
- }
- int Show(pila *p)
- {
- int cont;
- if(IsEmpty(p))
- return 0;
- else
- for(cont=0;cont<TAMMAX;cont++)
- {
- printf("%d.- %d \n", cont+1, p->elementos[cont]);
- }
- }
- void menu(int *popc)
- {
- printf("\n Menu \n \n");
- printf(" 1.- Ingresar Dato\n ");
- printf("2.- Quitar Dato\n ");
- printf("3.- Mostrar Tope\n ");
- printf("4.- Mostrar Pila\n ");
- printf("5.- Borrar Pila\n ");
- scanf("%d", popc);
- }
- main()
- {
- int dato, opc, cont, mas;
- Initialize(&Pila);
- menu(&opc);
- switch(opc)
- {
- case 1:
- for(cont=1;cont<TAMMAX;cont++)
- {
- printf("Ingrese un dato: ");
- scanf("%d", &dato);
- Push(&Pila, dato);
- printf("\nDesea ingresar otro dato? (1/0)");
- scanf("%d", &mas);
- if(mas==0)
- break;
- }
- break;
- case 2:
- for(cont=1;cont<TAMMAX;cont++)
- {
- printf("Ingrese el primer dato: ");
- scanf("%d", &dato);
- Pop(&Pila, dato);
- printf("\nDesea quitar otro dato? (1/0)");
- scanf("%d", &mas);
- if(mas==0)
- break;
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment