Matheus, your understanding is correct, it’s an excerpt from a FILA implementation algorithm, as you may know, the concept tells us:
They are data structures of type FIFO (first-in first-out), where the
the first item to be inserted shall be the first item to be removed, or
is, add items at the end and remove from the beginning.
Basically the FILAS have two operations:
- Enqueue: insert an element at the end of the queue.
- Dequeue: remove an element from the queue start.
The snippet of your code is an operation Dequeue, removal, and as mentioned above, you will have to remove the first element for this inicio++
and after that you will have to decrease the queue size so qtdeElementos--
See its full code, in Java language, taken from this link:
import javax.swing.*;
class Fila{
int inicio;
int fim;
int tamanho;
int qtdeElementos;
int f[];
public Fila(){
inicio = fim = -1;
tamanho = 100;
f = new int[tamanho];
qtdeElementos = 0;
}
public boolean estaVazia(){
if (qtdeElementos == 0){
return true;
}
return false;
}
public boolean estaCheia(){
if (qtdeElementos == tamanho - 1){
return true;
}
return false;
}
public void adicionar(int e){
if (! estaCheia()){
if (inicio == -1){
inicio = 0;
}
fim++;
f[fim] = e;
qtdeElementos++;
}
}
public void remover(){
if (! estaVazia() ){
inicio++;
qtdeElementos--;
}
}
public void mostrar(){
String elementos = "";
for (int i = inicio; i<=fim; i++) {
elementos += f[i]+ " - ";
}
JOptionPane.showMessageDialog(null, elementos);
}
}
If there is any doubt, a picture is worth a thousand words, see the detailed explanations here: