forked from jieniyimiao/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex10_27.cpp
More file actions
27 lines (24 loc) · 728 Bytes
/
Copy pathex10_27.cpp
File metadata and controls
27 lines (24 loc) · 728 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
//
// ex10_27.cpp
// Exercise 10.27
//
// Created by pezy on 12/13/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// In addition to unique, the library defines function named unique_copy that
// takes a third iterator denoting a destination into which to copy the unique elements.
// Write a program that uses unique_copy to copy the unique elements from
// a vector into an initially empty list.
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
int main()
{
std::vector<int> vec{1,1,3,3,5,5,7,7,9};
std::list<int> lst;
std::unique_copy(vec.begin(), vec.end(), back_inserter(lst));
for (auto i : lst)
std::cout << i << " ";
std::cout << std::endl;
}