Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Uzyj klasy queue. Opracować funkcję OdwrocKol(…), która odwraca kolejność elementów w kolejce. Napisać program sprawdzający tę funkcję. W kolejce mają być ustawiane elementy typu string, wczytywane z dołączonego pliku
- */
- #include <iostream>
- #include <string>
- #include <queue>
- #include <fstream>
- #include <stdlib>
- using namespace std;
- queue<string> odwrocKolejke(queue <string> kolejka){
- queue<string> tmp = kolejka, tmp2;
- vector<string> wynik;
- while(!tmp.empty()){
- wynik.push_back(tmp.front());
- tmp.pop();
- }
- while(!wynik.empty()){
- tmp2.push(wynik.back());
- wynik.pop_back();
- }
- return tmp2;
- }
- void pokazKolejke(queue <string> kolejka){
- queue<string> tmp = kolejka;
- while(!tmp.empty()){
- cout << tmp.front() << " ";
- tmp.pop();
- }
- cout << endl;
- }
- int main(){
- queue <string> kolejka, kolejka2;
- fstream file;
- file.open( "text.txt" , std::ios::in | std::ios::out);
- if( file.good() == false )exit (0);
- string line;
- while(getline(file,line)){
- kolejka.push(line);
- }
- pokazKolejke(kolejka);
- kolejka2 = odwrocKolejke(kolejka);
- pokazKolejke(kolejka2);
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment