Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class colaCircular{
- private static int MAXIMO=99;
- protected int frente;
- protected int fin ;
- protected Object[] ListaCola;
- //avanza una posicion
- public int siguiente (int r)
- {
- return(r+1)%MAXIMO;
- }
- //inicializa la cola vacia
- public colaCircular(){
- frente=0;
- fin=MAXIMO-1;
- ListaCola= new Object [MAXIMO];
- }
- //operaciones de modificacion de la cola
- public void insertar (Object elemento) throws Exception{
- if(!colaLlena()){
- fin=siguiente(fin);
- ListaCola[fin]=elemento;
- }else throw new Exception("Overflow en la cola");
- }
- public Object quitar()throws Exception{
- if(!colaVacia()){
- Object tm= ListaCola[frente];
- frente= siguiente (frente);
- return tm;
- }else throw new Exception(" Cola vacia ");
- }
- public void borrarCola(){
- frente=0;
- fin=MAXIMO-1;
- }
- //acceso a la cola
- public Object frenteCola()throws Exception{
- if (!colaVacia()){
- return ListaCola[frente];
- }else throw new Exception(" Cola vacia ");
- }
- public Object finCola()throws Exception{
- if (!colaVacia()){
- return ListaCola[fin];
- }else throw new Exception(" Cola vacia ");
- }
- //metodos de verificacion del estado de la cola
- public boolean colaVacia(){
- return frente==siguiente(fin);
- }
- //comprueba si esta llena
- public boolean colaLlena(){
- return frente==siguiente(siguiente(fin));
- }
- public void mostrarCola()throws Exception{
- if(!colaVacia()){
- for (int i=frente;i<=fin;i++){
- System.out.print(ListaCola[i]+ " " );
- }
- System.out.println( " ");
- }
- else
- throw new Exception(" Cola Vacia ");
- }
- public int tamaƱoCola()throws Exception{
- if(!colaVacia()){
- return fin-frente;
- }
- else
- throw new Exception ("Cola Vacia ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement