• Viernes 17 de Mayo de 2024, 05:53

Autor Tema:  Pilas C++ Utilizando Estructuras  (Leído 1909 veces)

nayez

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Pilas C++ Utilizando Estructuras
« en: Jueves 20 de Octubre de 2011, 00:59 »
0
Hola q tal buenas tardes quisiera q me ayudaran con este programa, el programa debe de permitir insertar 4 elementos y despues visualizarlos de acuerdo al orden en que fueron insertados.
Estou utilizando el compilador DEV C++
Anexo el codigo
Código: [Seleccionar]
//IMPLEMENTA UNA PILA
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
struct pilas
{
       int x;
}pi[3];
//prototipos de función
void llenar(pilas);
int extraer(pilas);
int tope=-1;

int main()
{

  cout<<"LLENAR PILA"<<endl;

  while(tope<3)
  {
                 for (int i=0; i<3; i++)
                 {
                     cin>>pi[i].x;
                     llenar (pi[i]);
                 }
  }

  cout<<"Pulsar cualquier tecla para continuar";
  getche();
  system ("CLS");

  cout<<"Datos de la pila"<<endl;
  for (int i=0; i<3; i++)
  {
      extraer(pi[i]);
  }
  getche ();
  return 0;
}//fin main()

void llenar(pilas)
{
  if(tope+1 >=3)
  cout<<"Pila llena"<<endl;
  pi[++tope]=pi[3];
}

int extraer(pilas)
{
  while(tope>=0)
  {
                for (int i=0; i<3; i++)
                {
                    cout <<pi[i].x;
                    pi[--tope]=pi[3];
                    getche ();
                }
               
                if(tope==-1)
                cout<<"Pila vacia";
  }
}
« última modificación: Jueves 20 de Octubre de 2011, 01:05 por nayez »