/JULIO CESAR LEYVA RODRIGUEZ
//PILA CON ESTRUCTURAS
#include
#include
#include
#define max 5
typedef int tipodatopila;
typedef struct pila
{
int tope;
int *pila;
};
//RESETEA LA PILA
void resetearpila(pila *resetea)
{
resetea->tope=-1;
gotoxy(40,6); cout<<"SE HA RESETEADO LA PILA";
}
//PILA VACIA
int pilavacia(pila *vacia)
{
if(vacia->tope==-1)
{
return (1);
}
else
{
return (0);
}
}
//PILA LLENA
int pilallena(pila *llena)
{
if(llena->tope==max-1)
{
return (1);
}
else
{
return (0);
}
}
//PUSH
void push(pila *push, tipodatopila dato)
{
(push->tope)++;
*(push->pila+push->tope)=dato;
}
//INSERTAR EL DATO
void insertareldato(pila *insertar)
{
tipodatopila dato;
if(pilallena(insertar)==1)
{
gotoxy(40,6); cout<<"LA PILA ESTA LLENA";
}
else
{
gotoxy(40,6); cout<>dato;
push(insertar,dato);
}
}
//POP
tipodatopila pop(pila *pop)
{
tipodatopila dato;
dato=*(pop->pila+pop->tope);
(pop->tope)–;
return(dato);
}
//BORRAR
void borrar(pila *borrar)
{
if(pilavacia(borrar)==1)
{
gotoxy(40,6); cout<<"LA PILA ESTA VACIA";
}
else
{
gotoxy(40,6); cout<<"EL DATO "<<pop(borrar)<<" HA SIDO ELIMINADO";
}
}
//MOSTRAR PILA
void mostrarpila(pila *mostrar)
{
if(pilavacia(mostrar)==1)
{
gotoxy(20,6); cout<<"NO HAY DATOS";
}
else
{
for(int x=0; xtope+1; x++)
{
gotoxy(40,5+x); cout<pila[x];
}
}
}
//MENU
void menu(pila *menu)
{
int op;
do
{
clrscr();
gotoxy(20,5); cout<<"MENU";
gotoxy(1,6); cout<<"1. RESETEAR PILA";
gotoxy(1,7); cout<<"2. INSERTAR DATO";
gotoxy(1,8); cout<<"3. BORRAR DATO";
gotoxy(1,9); cout<<"4. VER PILA";
gotoxy(1,10); cout<<"ELIGA UNA OPCION [ ]";
gotoxy(20,10); cin>>op;
switch(op)
{
case 1:
resetearpila(menu);
gotoxy(40,7); getch();
break;
case 2:
insertareldato(menu);
getch();
break;
case 3:
borrar(menu);
getch();
break;
case 4:
mostrarpila(menu);
getch();
break;
}
}
while(op!=5);
}
main()
{
pila pilota;
tipodatopila pila[max];
pilota.pila=&pila[0];
menu(&pilota);
}
Deja un comentario