forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex9_20.cpp
More file actions
28 lines (24 loc) · 679 Bytes
/
Copy pathex9_20.cpp
File metadata and controls
28 lines (24 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// ex9_20.cpp
// Exercise 9.20
//
// Created by pezy on 12/3/14.
//
// @Brief Write a program to copy elements from a list<int> into two deques.
// The even-valued elements should go into one deque and the odd ones into the other.
#include <iostream>
#include <deque>
#include <list>
using std::deque; using std::list; using std::cout; using std::cin; using std::endl;
int main()
{
list<int> l{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
deque<int> odd, even;
for (auto i : l)
(i & 0x1 ? odd : even).push_back(i);
for (auto i : odd) cout << i << " ";
cout << endl;
for (auto i : even)cout << i << " ";
cout << endl;
return 0;
}