Beruflich Dokumente
Kultur Dokumente
h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
using namespace std;
int insertar( float datoen, int *posi);
int extraer (float *datosal, int *posi);
int i,n,m;
float *pilon, *tope, *ultima, *aux;
int limite;
cout.setf(ios::fixed);
int i, posi, exito;
char select = ' ';
float datoen, datosal;
cout << " INDICA LA CANTIDAD DE ELEMENTOS QUE TENDRA EL ARREGLO DE DATOS ";
cin >> limite;
// solicitud de asignaci�n din�mica de memoria,
// con la cantidad "LIMITE " de localidades para flotantes
// pilon = (float *) calloc(limite, sizeof(float));
pilon = new float(limite);
if(!pilon)
{
cout << "\n LA ASIGNACION DE MEMORIA DINAMICA NO FUE CORRECTA, ";
cout << " SE SUSPENDE LA EJECUCION DEL PROGRAMA";
system("pause");
return 0;
}
ultima = pilon + (limite-1);
tope =pilon;
cout << endl<<" valor de la direcci�n inicial = "<<tope;
cout << endl<<" valor de la direcci�n final = "<<ultima;
posi = -1;
getche();
while (select != '4')
{
system("cls");
cout <<"\n PROGRAMA QUE SIMULA UNA PILA UTILIZANDO ARREGLOS \n ";
cout <<" SELECCIONE LA OPERACION CON PILAS \n\n";
cout <<" INSERTAR UN DATO EN LA PILA (1) \n";
cout <<" EXTRAER UN DATO DE LA PILA (2) \n";
cout <<" DESPLEGAR EL ESTADO DE LA PILA (3) \n";
cout <<" SALIR DEL PROGRAMA (4) \n";
cout <<" OPCION SELECCIONADA??";
select = getch();
switch(select)
{
case '1': //inserci�n de un dato en la pila
cout <<"\n \n TECLEA EL DATO QUE SERA INSERTADO EN LA PILA : ";
cin>> datoen;
exito =insertar(datoen, &posi);
if( exito == -1)
{ cout << endl<< " ERROR EN INSERCCION" ; getche(); break;}
return 0;
}
{
cout << "\n LA PILA ESTA LLENA, NO SE PUDO INSERTAR EL NUEVO
DATO"<<endl;
return -1;
}
(*tope)++;
pila[(*tope)]= dato;
return 0;
}