Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fila {
- private static final int MAX = 100;
- private int tamanho;
- private int inicio;
- private int fim;
- private int vetor[] = new int [MAX];
- public Fila(){
- this.tamanho = 0;
- this.inicio = 0;
- this.fim = -1;
- }
- public int getTamanho(){
- return this.tamanho;
- }
- public boolean vaziaFila(){
- return this.tamanho == 0;
- }
- public boolean cheiaFila(){
- return this.tamanho == MAX;
- }
- public void insereFila(int valor){
- if(this.cheiaFila()){
- System.out.println("Fila cheia.");
- }
- this.fim = (this.fim + 1) % MAX;
- this.vetor[ this.fim ] = valor;
- this.tamanho++;
- }
- public int removeFila(){
- if(this.vaziaFila()){
- System.out.println("Fila vazia.");
- return 0;
- }
- int i = this.vetor[ this.inicio ];
- this.inicio = (this.inicio + 1) % MAX;
- this.tamanho--;
- return i;
- }
- public int primeiroFila(){
- if(this.vaziaFila()){
- return 0;
- }else{
- return this.vetor[ this.inicio ];
- }
- }
- public void mostraFila(){
- if(this.vaziaFila()){
- System.out.println("Fila vazia.");
- }
- int posicao = 1;
- for(int i = this.inicio; i != ( (this.fim + 1) % MAX ); i++, posicao++){
- System.out.println("Posição: "+ posicao +" / Valor: " + vetor[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement