将list中的元素按奇偶分到两个deque中
Practice 9.20
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iterator>
#include <cmath>
#include <deque>
#include <cstring>
#include <forward_list>
using namespace std;
void fun(list<int> lst, deque<int> & q1, deque<int> & q2) {
for(auto i : lst) {
if(i&1) {
q1.push_back(i);
}
else {
q2.push_back(i);
}
}
}
void print(deque<int> deq) {
for(auto i : deq) {
cout << i << " ";
}
cout << endl;
}
int main() {
list<int> ilst = {0, 1, 2, 3, 4, 5, 6, 7, 8};
deque<int> ideq1;
deque<int> ideq2;
fun(ilst, ideq1, ideq2);
cout << "This is deque_1: " << endl;
print(ideq1);
cout << "This is deque_2: " << endl;
print(ideq2);
return 0;
}
Outpt
This is deque_1:
1 3 5 7
This is deque_2:
0 2 4 6 8
Suffering is the most powerful teacher of life.