* @(#)Colas.java
*
*
* @author Heryck Misael Muñoz Mora
* @version 1.00 2014/4/9
*/
import java.util.Scanner;
public class Colas {
/**
* Creates a new instance of <code>Colas</code>.
*/
public Colas() {
}
/**
* @param args the command line arguments
*/
public static int frent=0, fin=0;
public static void main(String[] args) {
// TODO code application logic here
Scanner ent = new Scanner (System.in);
int opcion, max;
int [] cola;
System.out.println("\nCantidad de elementos de la Cola :"); // Ingrese el tamaño de la pila
max = ent.nextInt();
cola = new int[max]; // pila es igual a la entrada del tamaño en "n"
System.out.println("\n Cola creada con exito.....\n");
do{
System.out.println("\n");
System.out.println("1.- INSERTAR COLA");
System.out.println("2.- ELIMINAR COLA");
System.out.println("3.- PRESENTAR PILA");
System.out.println("4.- LIMPIAR PILA");
System.out.println("5.- TERMINAR");
System.out.println("6.- DEFAULT\n");
opcion = ent.nextInt();
switch (opcion)
{
case 1: Insert(cola, max);
break;
case 2: Elim(cola);
break;
case 3: presentar (cola);
break;
case 4: frent=0;
fin=0;
break;
case 5:
break;
default:
System.out.println("Opcion equivocada");
} // cierra el switch
}
while(opcion != 5); // cierra el do
} // cierra el main
public static void Insert(int [] c, int m)
{
Scanner ent = new Scanner(System.in); // AQUI SE CREA EL OBJETO DE TIPO SCANNER, PARA SER INTRODUCIDO CON EL TECLADO
if (fin < m)
{
System.out.print("Ingrese valor :");
c[fin]=ent.nextInt(); // LEE UN ENTERO, DEPOSITANDOLO EN EL ARREGLO C, DE TIPO ENTERO, CREADO CON EL SCANNER
fin++;
if (fin == 1)
{
frent = fin;
}
}
else
{
System.out.print("Desbordamiento de Cola \nTodo lleno");
}
}
public static void Elim (int [] c)
{
if(frent > fin || fin == 0)
{
System.out.print("Elemento Cola esta vacia \nSin Datos"); // System.out.print("NO HAY DATOS");
}
else
{
System.out.println("Se elimina el elemento"+frent); // System.out.print("ELEMENTO A ELIMINAR = " + C [ FRENTE - 1]);
System.out.println("c [ " + frent + " ] = " + c [ frent-1 ] );
frent++;
}
}
public static void presentar (int [] c)
{
if (frent > fin || fin == 0)
{
System.out.println("COLA VACIA");
}
else
{
for ( int i = frent; i<= fin; i++)
{
System.out.println( "cola [ " + i + " ]" + c [i - 1] );
}
}
}
}
No hay comentarios:
Publicar un comentario