Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright [2015] <Salvatore Junior Amore>
- template <typename T>
- class Fila {
- private:
- T *fila;
- int const MaxFila = 100;
- int ctrl = -1;
- int tamanho;
- int var = 0;
- public:
- Fila() {
- fila = new T[tamanho];
- tamanho = MaxFila;
- }
- Fila<T>(int tam) {
- fila = new T[tam];
- tamanho = tam;
- }
- void inclui(T dado) {
- if(filaCheia()) {
- throw 0;
- } else {
- ctrl++;
- fila[ctrl] = dado;
- }
- }
- T retira() {
- if(filaVazia()) {
- throw 1;
- } else {
- T inicio = fila[0];
- while (var != ctrl) {
- fila[var] = fila[var+1];
- var++;
- }
- ctrl--;
- var = 0;
- return inicio;
- }
- }
- T ultimo() {
- if(filaVazia()) {
- throw 1;
- } else {
- return fila[ctrl];
- }
- }
- int getUltimo() {
- if(filaVazia()) {
- throw 1;
- } else {
- return ctrl;
- }
- }
- bool filaCheia() {
- return (ctrl == tamanho - 1);
- }
- bool filaVazia() {
- return(ctrl == -1);
- }
- void inicializaFila() {
- ctrl = -1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement