ColaGenerica

class ColaGenerica{ public int max; protected Object dret; public Objectc[]; public int fre= -1; public intfin = -1; public ColaGenerica(){ max=20; c=new Object [max]; } public ColaGenerica(int n){ max=n; c=new Object [max]; } public boolean colallena(int fin,int max){ booleanllena; if(fin==max-1) llena=true; else llena=false; returnllena; } public boolean colavacia(int fre){ boolean vacia; if (fre==-1) vacia=true;

else vacia=false; return vacia; } public boolean inscola(Objectdato){ if(fin==max-1) returnfalse; fin++; c[fin] = dato; if(fin==0) fre=0; returntrue; } public boolean retcola(){ if (fre==-1) returnfalse; dret=c[fre]; if (fre==fin){ fre=-1; fin=-1; } else fre++; returntrue; } }

Cola

import java.util.*; public classCola { private static int op; private static int num; public static void main( String args[] ){ Scanner leer = new Scanner(System.in);

ColaGenerica obj = new ColaGenerica(); do{ menu(); op = leer.nextInt();

switch(op){ case1: System.out.println("Numero a insertar" ); num = leer.nextInt(); if(obj.inscola(num)){ System.out.println( "fre"+obj.fre+"fin"+obj.fin+"aux"+obj.max ); System.out.println( "El numero "+num+" se inserto en la cola ["+obj.dret+"]" ); System.out.println(); } else{ System.out.println("Cola llena" ); } break; case2: if(obj.retcola()){

System.out.println( "El dato retirado fue: "+obj.dret); } else{ System.out.println( "Cola vacia" ); } break; } } while(op!= 3); }

public static void menu(){ System.out.println( "\t Menupara colas \n" ); System.out.println("1.- Insertar" ); System.out.println("2.- Retirar" ); System.out.println("3.- Estado" );

System.out.println("\n Selecciona" ); } }

Sign up to vote on this title
UsefulNot useful