Programa desarrollado en lenguaje C++, que soporta unicamente valores de tipo entero(int), logrando almacenar en su ejecucion 5 enteros, este valor se puede modificar, cambiando el valor de MAX al valor que desee.
#include < conio.h >
#include < iostream.h >
#include < stdio.h >
#define MAX 5
class pila
{
public:
int tope;
int x[MAX];
public:
int insertar(int x[], int tope);
int eliminar(int x[], int tope);
void recorre(int x[],int tope);
};
void main()
{
pila ob;
ob.tope=-1;
char op;
do
{
clrscr();
gotoxy(35,8);cout<<"P I L A S";
gotoxy(30,11);cout<<"1.- INSERTAR";
gotoxy(30,13);cout<<"2.- ELIMINAR";
gotoxy(30,15);cout<<"3.- RECORRE";
gotoxy(40,20);cout<<"PRESIONE 'ESC' PARA SALIR";
op=getch();
switch(op)
{
case '1':ob.tope=ob.insertar(ob.x,ob.tope);
break;
case '2':ob.tope=ob.eliminar(ob.x,ob.tope);
break;
case '3':ob.recorre(ob.x,ob.tope);
break;
}
}while(op!=27);
}
int pila::insertar(int x[],int tope)
{
clrscr();
if(tope < MAX-1 )
{
tope=tope+1;
cout<<"ingrese dato: ";
cin>>x[tope];
}
else
{
gotoxy(25,10);cout<<"Pila llena no se puede insertar";
getch();
}
return(tope);
}
int pila::eliminar(int x[], int tope)
{
clrscr();
if(tope>-1)
{
tope=tope-1;
gotoxy(25,10);cout<<"descargando pila....!!";
gotoxy(25,12);cout<<"solo quedan "<< tope+1 <<" datos";
getch();
}
else
{
gotoxy(30,10);cout<<"La pila esta vacia";
getch();
}
return(tope);
}
void pila::recorre(int x[],int tope)
{
clrscr();
if(tope >-1)
{
for(int i=0;i<=tope;i++)
{
cout<< x[i] <<"\n";
getch();
}
else
{
gotoxy(30,10);cout<<"LA PILA ESTA VACIA";
getch();
}
}











0 Responses So Far: