lunes, 24 de octubre de 2016

COLA 

las colas tambien son llamadas FIFO (first in first out), que quiere decir el primero que entra es el primero que sale.


public class cola {
    private Object []repCola;
    private int cabCola;
    private int maxCola;
    public cola()
    {
       this.cabCola=0;
       this.maxCola=10;
       this.repCola=new Object[this.maxCola];
    }
     public cola(int mC)
    {
       this.cabCola=0;
       this.maxCola=mC;
       this.repCola=new Object[this.maxCola];
    }
    public boolean EstaLLena ()
    {
        boolean estado=false;
        if(this.cabCola>=this.maxCola)
            estado=true;
        return estado;
    
    }
    public boolean EstaVacia ()
    {
       boolean estado=false;
       if(this.maxCola==0)
           estado=true;
       return estado;
    }
    public boolean Meter(Object e)
    {
          boolean enCola =false;
          if(!this.EstaLLena())
            {
               this.repCola[this.cabCola]=new Object ();
               this.repCola[this.cabCola++]=e;
               enCola =true;
            }
     return enCola ;
    }
    public Object sacar()
    {
        Object tmpElemCola =null;
        if(!this.EstaVacia())
          {
            tmpElemCola=this.repCola[0];
            for(int i=0;i

No hay comentarios:

Publicar un comentario