Ну, если дек считать за очередь...
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| #include <iostream>
#include <deque>
#include <cstdlib>
#include <algorithm>
int pred(){return rand()%1000;}
bool isntodd(int x){return x&1;}
int main(){
srand( time(0) );
std::deque<int> arr(8);
generate(arr.begin(),arr.end(),pred);
std::cout << "Before:\n";
for (std::deque<int>::iterator it = arr.begin(); it != arr.end(); ++it)
std::cout << *it << ' ';
arr.erase(remove_if(arr.begin(),arr.end(),isntodd),arr.end());
std::cout << "\nAfter:\n";
for (std::deque<int>::iterator it = arr.begin(); it != arr.end(); ++it)
std::cout << *it << ' ';
return 0;
} |
|