Created
March 28, 2011 00:24
-
-
Save ProgDan/889805 to your computer and use it in GitHub Desktop.
Exemplo: STL Queue
This file contains hidden or 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
| #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