Last active
August 29, 2015 14:20
-
-
Save rogerioagjr/ba4cb6ed4a408738f9ef to your computer and use it in GitHub Desktop.
Fila
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAXT 1000100 // defino o tamanho limite da fila como 1000100 | |
int fila[MAXT], ini=1, fim; // declaro as variáveis que vou usar | |
// função front: retorna o primeiro elemento da fila | |
int front{ return fila[ini]; } // basta retornar o elemento na posição ini | |
// função back: retorna o último elemento da fila | |
int back(){ return fila[fim]; } // basta retornar o elemento na posição fim | |
// função size: retorna o tamanho da fila | |
int size(){ return fim-ini+1; } // basta retornar a diferença entre fim e ini mais 1 | |
// função push: insere um elemento no fim da fila | |
void push(int x){ fila[++fim]=x; } // faço fim receber a próxima posição e lá coloco o elemento x | |
// função pop: retira o primeiro elemento da fila | |
void pop(){ if(size()>0) ini++; } // faço o começo da receber a p´roxima posição | |
// função clear: retira todos os elementos da fila | |
void clear(){ ini=1; fim=0; } // basta fazermos ini e fim assumirem os seus valores iniciais |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment