miércoles, 16 de marzo de 2011

Estructura de Datos 16/Marzo/2011

Estructura de Dato de una Cola en Java.

Que opinan de este código. Que hay que Arreglar?



package colas;
import java.util.*;
import java.io.*;


class EstructCola{

private int frente = -1;
private int fin = -1;
public int limite =-1;
public Object c[];


public EstructCola(){
limite = 100;
c = new Object[limite];
}


public EstructCola( int limite ){
this.limite = limite;
c = new Object[limite];
}


public boolean crear(){
if( this.c != null )
return true;
else
return false;
}


public EstructCola crear( int limite ){
EstructCola estructCola = new EstructCola( limite );
return estructCola;
}


public boolean encolar( int elemento ){
boolean confirmacion = false;


if( ( this.fin+1 ) < ( this.limite ) ){

if( this.frente == -1 ) this.frente = this.frente + 1;

this.fin = this.fin + 1;
this.c[ this.fin ] = elemento;
confirmacion = true;
}

System.out.println( "Se encolo elemento:: " + this.c[this.fin ] + " :: en pocision ::" + this.fin );
return confirmacion;
}



public boolean desencolar(){
boolean confirmacion = false;

if( this.frente == this.fin )
System.out.println("EstructCola::desencolar::msg::No existen elementos...");
else{
this.frente = this.frente + 1;
System.out.println( "Elemento atendido::" + this.c[ this.frente ] + "::en pocisión :: " + this.frente );
confirmacion = true;
}

return confirmacion;
}



public boolean isVaciaCola(){

if( this.frente == this.fin )
return true;
else
return false;
}


public boolean isVaciaCola( EstructCola estrucCola ){

if( ( estrucCola.frente == estrucCola.fin ) || estrucCola == null )
return true;
else
return false;
}



public void imprimirCola(){
if( this.frente != this.fin && this.frente != -1 && this.fin != -1 ){

for(int i= this.frente; i<= this.fin; i++)
System.out.println( " " + this.c[i] + " " );

}else System.out.println( "EstructCola::imprimirCola::msg::No existen elementos en la cola. " );

}



}

No hay comentarios:

Publicar un comentario