Advertisement
Vesker

Fila de Vetor

Apr 4th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. // Copyright [2015] <Salvatore Junior Amore>
  2. template <typename T>
  3. class Fila {
  4.  private:
  5.     T *fila;
  6.     int const MaxFila = 100;
  7.     int ctrl = -1;
  8.     int tamanho;
  9.     int var = 0;
  10.  
  11.  
  12.  public:
  13.     Fila() {
  14.     fila = new T[tamanho];
  15.     tamanho = MaxFila;
  16.     }
  17.     Fila<T>(int tam) {
  18.     fila = new T[tam];
  19.     tamanho = tam;
  20.     }
  21.     void inclui(T dado) {
  22.     if(filaCheia()) {
  23.     throw 0;
  24.     } else {
  25.     ctrl++;
  26.     fila[ctrl] = dado;
  27.         }
  28.     }
  29.     T retira() {
  30.     if(filaVazia()) {
  31.     throw 1;
  32.     } else {
  33.     T inicio = fila[0];
  34.     while (var != ctrl) {
  35.     fila[var] = fila[var+1];
  36.     var++;
  37.     }
  38.     ctrl--;
  39.     var = 0;
  40.     return inicio;
  41.                 }
  42.     }
  43.     T ultimo() {
  44.     if(filaVazia()) {
  45.     throw 1;
  46.     } else {
  47.     return fila[ctrl];
  48.         }
  49.     }
  50.     int getUltimo() {
  51.     if(filaVazia()) {
  52.     throw 1;
  53.     } else {
  54.     return ctrl;
  55.         }
  56.     }
  57.     bool filaCheia() {
  58.     return (ctrl == tamanho - 1);
  59.     }
  60.     bool filaVazia() {
  61.     return(ctrl == -1);
  62.     }
  63.     void inicializaFila() {
  64.     ctrl = -1;
  65.     }
  66. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement