class Cola
{
//Cola Dinamica simple. (Implementada con listas enlazadas)
int[] vec;
int tam;
int p ;
int u;
public Cola(int Tam)
{
p = u = -1;
tam = Tam;
vec = new int[tam];
}
//public Cola()
//{
// p = u = -1;
//}
public bool EstaLlena()
{
if (u >= tam - 1)
return true;
return false;
}
public bool EstaVacia()
{
if (p == -1)
return true;
return false;
}
public bool Agregar(int dato)
{
if (!EstaLlena())
{
vec[++u] = dato;
if (u == 0)
p = 0;
return true;
}
return false;
}
public bool Extraer(ref int dato)
{
dato = 0;
if (!EstaVacia())
{
dato = vec[p];
if (p == u)
{
p = -1;
u = p;
}
else
p++;
return true;
}
return false;
}
}
No hay comentarios:
Publicar un comentario