/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package automatapilacombinado;
/**
*
* @author Edson
*/
public class pila {
int tope=-1;
int vec[];
pila(int max)
{
vec=new int [max];
}
public boolean llena()
{
if (tope==vec.length-1)
return true;
else
return false;
}
public boolean vacia()
{
if (tope==-1)
return true;
else
return false;
}
public void push(int dato)
{
if (llena()== true)
System.out.println("Overflow");
else
if (tope==-1)
{
tope=0;
vec[tope]=dato;
}
else
{
tope++;
vec[tope]=dato;
}
}
public int pop()
{
int aux;
if (vacia()==true)
{
System.out.println("La pila esta vacia");
return -1;
}
else
{
aux=vec[tope];
tope--;
}
return aux;
}
public void Imprime_Datos()
{
if(vacia()==true)
{
System.out.println("Ingrese los datos:");
}
else
for(int Contador=0;Contador
System.out.println("Los valores son:"+vec[Contador]);
}
}
No hay comentarios:
Publicar un comentario