-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathex10_27.cpp
More file actions
28 lines (25 loc) · 767 Bytes
/
ex10_27.cpp
File metadata and controls
28 lines (25 loc) · 767 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
//
// 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{3, 5, 1, 5, 1, 7, 3, 7, 9};
std::list<int> lst;
std::sort(vec.begin(), vec.end());
std::unique_copy(vec.begin(), vec.end(), back_inserter(lst));
for (auto i : lst) std::cout << i << " ";
std::cout << std::endl;
}