Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <ctime>
- #include <fstream>
- #include <string>
- #include <list>
- #include <queue>
- #include <stack>
- using namespace std;
- void printQueue(queue<int> q)
- {
- //printing content of queue
- while (!q.empty()) {
- cout << q.front() << "\t";
- q.pop();
- }
- cout << endl;
- }
- // Function to reverse the queue
- void reverseQueue(queue<int>& Queue)
- {
- stack<int> Stack;
- while (!Queue.empty()) {
- Stack.push(Queue.front());
- Queue.pop();
- }
- while (!Stack.empty()) {
- Queue.push(Stack.top());
- Stack.pop();
- }
- }
- int main()
- {
- srand((unsigned)time(0));
- setlocale(0, "");
- string path = "input.txt";
- int number = 0;
- list<int> l;
- ifstream fin;
- fin.open(path);
- float ch;
- int Count = 0;
- while (fin >> ch)
- Count++;
- fin.close();
- ifstream file(path);
- for (int i = 0; i < Count; i++) {
- file >> number;
- l.push_back(number);
- }
- for (auto i : l)
- cout << i << "\t";
- cout << endl;
- fin.close();
- queue<int> q;
- float sum = 0;
- for (auto i : l)
- sum += i;
- float average = sum / Count;
- cout << average << endl;
- for (auto i : l) {
- if (i < average)
- q.push(i);
- }
- reverseQueue(q);
- printQueue(q);
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment