ColaCircular - return (fin - inicio + MAXIMO) % MAXIMO; }...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.io.*; import java.util.Scanner; public class ColaCircular { private final int MAXIMO = 100; private int[] V; private int inicio; private int fin; public ColaCircular() { this.V = new int[MAXIMO + 1]; this.inicio = 0; this.fin = 0; } public boolean esVacia() { return inicio == fin; } public boolean esLlena() { return tamanio() == MAXIMO - 1; } public void adicionar(int a) { if (esLlena()) { System.out.println("Cola Llena! No se pudo adicionar."); } else { fin = (fin + 1) % MAXIMO; V[fin] = a; } } public int eliminar() { int a = Integer.MIN_VALUE; if (esVacia()) { System.out.println("Cola Vacia! No se pudo eliminar."); } else { inicio = (inicio + 1) % MAXIMO; a = V[inicio]; } return a; } public int tamanio() {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return (fin - inicio + MAXIMO) % MAXIMO; } private void copiar(ColaCircular B) { while (!B.esVacia()) { adicionar(B.eliminar()); } } public void leer() { Scanner in = new Scanner(System.in); System.out.print("Nro.Elementos: "); int n = in.nextInt(); System.out.println("Ingrese elementos:"); for (int i = 0; i < n; i++) { int a = in.nextInt(); adicionar(a); } } public void mostrar() { if (esVacia()) { System.out.println("Cola Vacia! No se puede mostrar nada."); } else { ColaCircular X = new ColaCircular(); while (!esVacia()) { int a = eliminar(); System.out.print(" " + a); X.adicionar(a); } this.copiar(X); System.out.println(""); } } }...
View Full Document

This note was uploaded on 09/19/2011 for the course ECONOMY JACKC0412 taught by Professor Wang during the Fall '08 term at Punjab Engineering College.

Page1 / 2

ColaCircular - return (fin - inicio + MAXIMO) % MAXIMO; }...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online