-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fila.cpp
58 lines (51 loc) · 940 Bytes
/
Fila.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <stdlib.h>
using namespace std;
template <class Tipo>
class Fila {
typedef struct tno{
Tipo num;
tno* prox;
}tno;
tno* inicio;
tno* fim;
public:
Fila (){
inicio = NULL;
}
void insere(Tipo x){
tno* temp = (tno*)malloc(sizeof(tno));
temp->num = x;
temp->prox = NULL;
if(inicio != NULL){
fim -> prox = temp;
fim = temp;
}else{
fim = temp;
inicio = temp;
}
}
Tipo remove(){
Tipo ret;
if(inicio != NULL){
tno* aux = inicio;
ret = aux->num;
inicio = inicio -> prox;
free(aux);
}
return ret;
}
friend ostream &operator<<( ostream &output, const Fila &fila ) {
output << "[";
if(fila.inicio != NULL){
output << fila.inicio -> num;
tno* aux = fila.inicio->prox;
while(aux != NULL){
output << ", "<< aux -> num;
aux = aux->prox;
}
}
output << "]";
return output;
}
};