Datos Personales

Nombre:Gabriel Alejandro Barrientos Medellin
Ciudad:Matamoros,Coahuila
Edad:20
Materia:Estructura de Datos

sábado, 26 de noviembre de 2011

class pila

class Pila

{

private int[] elementos = null;

private int tope;

public Pila()

{

elementos = new int[5];

tope = -1;

}

public Pila(int n)

{

if (n < 1)

n = 5;

elementos = new int[n];

tope = -1;

}

public int this[int index]

{

get { return elementos[index]; }

}

public int Maximo

{

get { return elementos.Length; }

}

public int Tope

{

get { return tope; }

}

public bool estaVacia()

{

return tope == -1;

}

public bool estaLlena()

{

return tope == elementos.Length - 1;

}

public bool Poner(int x)

{

if (estaLlena())

return false;



tope++;

elementos[tope] = x;

return true;

}



public bool Quitar(ref int x)

{

if (estaVacia())

return false;



x = elementos[tope];

tope--;

return true;

}


}


No hay comentarios:

Publicar un comentario