Cola Generic A

  • Uploaded by: Erika
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Cola Generic A as PDF for free.

More details

  • Words: 203
  • Pages: 4
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" ); } }

Related Documents

Cola Generic A
April 2020 6
Generic A
June 2020 3
Cola
April 2020 25
Cola
May 2020 30
Cola
November 2019 31

More Documents from ""

Resume
May 2020 18
Arduino.pdf
December 2019 26
Tema 4
June 2020 19
December 2019 28