Skip to content

Instantly share code, notes, and snippets.

@ProgDan
Created March 28, 2011 00:24
Show Gist options
  • Save ProgDan/889805 to your computer and use it in GitHub Desktop.
Save ProgDan/889805 to your computer and use it in GitHub Desktop.
Exemplo: STL Queue
#include <iostream>
#include <queue>
using namespace std;
int menu(){
int op;
cout << "Menu" << endl;
cout << endl << "1) Inserir elemento na fila";
cout << endl << "2) Remover elemento da fila";
cout << endl << "3) Exibir primeiro da fila";
cout << endl << "4) Exibir último da fila";
cout << endl << "0) Sair";
cout << endl << endl << "Qual sua opção? ";
cin >> op;
cout << endl;
return op;
}
void Inserir(queue<int> &F){
int v;
cout << "Qual o valor a ser inserido na fila? ";
cin >> v;
F.push(v);
}
int Remover(queue<int> &F){
int x;
x = F.front();
return x;
}
int Primeiro(queue<int> &F){
return F.back();
}
int main(int argc, char *argv[]){
queue<int> F;
int op, x;
do {
op = menu();
if (op >= 2 && op <= 4 && F.empty()){
cout << "File vazia" << endl;
system("pause");
}
else
switch (op){
case 1:
Inserir(F);
break;
case 2:
x = Remover(F);
cout << "Valor " << x << " removido da fila" << endl;
system("pause");
break;
case 3:
x = Primeiro(F);
cout << "Primeiro da fila: " << x << endl;
system("pause");
break;
case 4:
x = Ultimo(F);
cout << "Ultimo da fila: " << x << endl;
system("pause");
break;
}
} while(op != 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment