{
class colas
{
int[] vec;
int p, u, tam;
public colas(int n)
{
p = u = -1;
tam = n;
vec = new int[tam];
}
public bool agregar(int dato)
{
if(!esta_llena())
{
vec[++u]=dato;
if(u==0)
p=0;
return true;
}
return false;
}
public bool extraer(ref int dato)
{
if (!esta_vacia())
{
dato = vec[p];
if (p == u)
{
p = -1;
u = p;
}
else
p++;
return true;
}
return false;
}
public bool esta_llena()
{
if (u >= tam- 1)
return true;
return false;
}
public bool esta_vacia()
{
if (p == -1)
return true;
return false;
}
}
}
//-----------------------------------------------------
namespace cola
{
class Program
{
static void Main(string[] args)
{
colas cola = new colas(5);
int i;
Random r = new Random();
Console.WriteLine("agregar cola");
for (i = 0; i < 7; i++)
{
int dato = i + 5;
if (cola.agregar(dato))
Console.WriteLine("dato agregado" + dato);
else
Console.WriteLine("desbordamiento de la cola");
}
int d = 0;
Console.WriteLine("extrayendo datos");
if (cola.extraer(ref d))
Console.WriteLine("dato extraido" + d);
else
{
Console.WriteLine("sub desbordamiento la cola esta vacia");
}
Console.ReadKey();
}
}
}
y Random r = new Random();
ResponderEliminarpara que?
Este comentario ha sido eliminado por el autor.
ResponderEliminar