SlideShare a Scribd company logo
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
3
4
[KOSSA] C++ Programming - 17th Study - STL #3
6
http://www.cplusplus.com/reference/algorithm
7
template<class InputIterator, class Type>
InputIterator find(InputIterator _First, InputIterator _Last, const Type& _Val);
8
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
std::vector<int> V{ 10, 20, 30, 40, 50 };
auto it30 = std::find(V.begin(), V.end(), 30);
auto it25 = std::find(V.begin(), V.end(), 25);
if (it30 != V.end())
std::cout << "Find 30 !" << std::endl;
if (it25 != V.end())
std::cout << "Find 25 !" << std::endl;
}
9
template<class InputIterator, class Predicate>
InputIterator find_if(InputIterator _First, InputIterator _Last, Predicate _Pred);
10
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
std::vector<int> V{ 10, 20, 30, 40, 50 };
auto GT25 = [](int n) { return n > 25; };
auto itFI = std::find_if(V.begin(), V.end(), GT25);
if (itFI != V.end())
std::cout << (*itFI) << std::endl;
}
[KOSSA] C++ Programming - 17th Study - STL #3
12
http://www.cplusplus.com/reference/algorithm
13
template<class InputIterator, class Type>
InputIterator remove(InputIterator _First, InputIterator _Last, const Type& _Val);
14
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
std::vector<int> V{ 10, 20, 30, 40, 50 };
std::cout << "V.size() = " << V.size() << std::endl;
auto itR = std::remove(V.begin(), V.end(), 40);
if (itR != V.end())
{
std::cout << "After remove() : " << V.size() << std::endl;
V.erase(itR, V.end());
std::cout << "After erase() : " << V.size() << std::endl;
}
}
15
template<class InputIterator, class Predicate>
InputIterator remove_if(InputIterator _First, InputIterator _Last, Predicate _Pred);
16
#include <iostream>
#include <vector>
#include <algorithm>
void main()
{
std::vector<int> V{ 10, 15, 30, 45, 50 };
auto isOdd = [](int n) { return n % 2 == 1; };
auto itRI = std::remove_if(V.begin(), V.end(), isOdd);
if (itRI != V.end())
{
std::cout << "After remove_if() : " << V.size() << std::endl;
V.erase(itRI, V.end());
std::cout << "After erase() : " << V.size() << std::endl;
}
}
[KOSSA] C++ Programming - 17th Study - STL #3
18
http://www.cplusplus.com/reference/algorithm
19
template<class RandomAccessIterator, class Pr>
void sort(RandomAccessIterator _First, RandomAccessIterator _Last,
BinaryPredicate _Comp);
20
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
void main()
{
std::vector<int> V{ 10, 30, 15, 50, 45 };
for (auto it = V.begin(); it != V.end(); it++)
std::cout << (*it) << 't';
std::cout << std::endl;
std::sort(V.begin(), V.end(), std::less<int>());
for (auto it = V.begin(); it != V.end(); it++)
std::cout << (*it) << 't';
std::cout << std::endl;
}
21
template<class InputIterator1, class InputIterator2,
class OutputIterator, class BinaryPredicate>
OutputIterator merge(InputIterator1 _First1, InputIterator1 _Last1,
InputIterator2 _First2, InputIterator2 _Last2,
OutputIterator _Result, BinaryPredicate _Comp);
22
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <functional>
void main()
{
std::vector<int> V{ 10, 30, 15, 50, 45 };
std::sort(V.begin(), V.end(), std::less<int>());
std::deque<int> V2{ 13, 78, 57, 24, 69 };
std::sort(V2.begin(), V2.end(), std::less<int>());
std::vector<int> VR;
VR.resize(V.size() + V2.size());
auto isLess = [](int a, int b) { return a < b; };
std::merge(V.begin(), V.end(), V2.begin(), V2.end(), VR.begin(), isLess);
for (auto it = VR.begin(); it != VR.end(); it++)
std::cout << (*it) << 't';
std::cout << std::endl;
}
[KOSSA] C++ Programming - 17th Study - STL #3
24
http://www.cplusplus.com/reference/numeric
25
template<class InputIterator, class Type, class BinaryOperation>
Type accumulate(InputIterator _First, InputIterator _Last,
Type _Val, BinaryOperation _Binary_op);
26
#include <iostream>
#include <vector>
#include <numeric>
void main()
{
std::vector<int> V{ 1, 2, 3, 4};
int nSum = std::accumulate(V.begin(), V.end(), 0); // vector의 합
int nSum10 = std::accumulate(V.begin(), V.end(), 10); // 10 + vector의 합
auto multi = [](int a, int b) { return a * b; };
int nMulti = std::accumulate(V.begin(), V.end(), 1, multi); // 인자의 곱
auto nSqure = [](int a, int b) { return a + b * b; };
int nSumSqure = std::accumulate(V.begin(), V.end(), 0, nSqure); // 제곱의 합
}

More Related Content

PPTX
JavaScript Gotchas
DOCX
Contraints
PDF
New land of error handling in swift
PDF
Python 炒股指南
PDF
Improving the java type system
PPTX
3. chapter ii
DOC
Useful c programs
PPTX
4. chapter iii
JavaScript Gotchas
Contraints
New land of error handling in swift
Python 炒股指南
Improving the java type system
3. chapter ii
Useful c programs
4. chapter iii

What's hot (20)

PDF
VTU DSA Lab Manual
PDF
Python Anti patterns / tips / tricks
PDF
Compilation process
PDF
Introduction to Programming @ NTHUEEECamp 2015
PDF
2. Базовый синтаксис Java
DOCX
Catch and throw blocks
PPTX
Exceptional exceptions
PPTX
Session05 iteration structure
PPTX
4. pointers, arrays
PPTX
Namespaces
PDF
C++ L06-Pointers
PPTX
C Programming Language Step by Step Part 5
PDF
Getting started with LLVM using Swift / Алексей Денисов (Blacklane)
PDF
Print Star pattern in java and print triangle of stars in java
PDF
Java script obfuscation
PDF
Design patterns in javascript
PPTX
C Programming Language Part 4
PDF
05 1 수식과 연산자
PPT
Cquestions
PDF
C++ L04-Array+String
VTU DSA Lab Manual
Python Anti patterns / tips / tricks
Compilation process
Introduction to Programming @ NTHUEEECamp 2015
2. Базовый синтаксис Java
Catch and throw blocks
Exceptional exceptions
Session05 iteration structure
4. pointers, arrays
Namespaces
C++ L06-Pointers
C Programming Language Step by Step Part 5
Getting started with LLVM using Swift / Алексей Денисов (Blacklane)
Print Star pattern in java and print triangle of stars in java
Java script obfuscation
Design patterns in javascript
C Programming Language Part 4
05 1 수식과 연산자
Cquestions
C++ L04-Array+String
Ad

Similar to [KOSSA] C++ Programming - 17th Study - STL #3 (20)

PPTX
11. template
PDF
An Introduction to Part of C++ STL
PDF
maincpp include ListItemh include ltstringgt in.pdf
PPTX
15. map, unordered map, algorithms
PPTX
14. containers, vector, list
PDF
Lab 13 Practicing STLVector Container1a. Write a template func.pdf
PDF
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
PPTX
Advanced oops using c and c++.Pptx in Srm
PPTX
Time and Space Complexity Analysis.pptx
PDF
include ltfunctionalgt include ltiteratorgt inclu.pdf
PPTX
DOCX
Write a program to find the number of comparisons using the binary se.docx
DOC
Oops lab manual2
PPT
standard template library(STL) in C++
PDF
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
KEY
Matuura cpp
PDF
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
DOCX
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
PPTX
Object Oriented Programming Using C++: C++ STL Programming.pptx
PDF
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
11. template
An Introduction to Part of C++ STL
maincpp include ListItemh include ltstringgt in.pdf
15. map, unordered map, algorithms
14. containers, vector, list
Lab 13 Practicing STLVector Container1a. Write a template func.pdf
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
Advanced oops using c and c++.Pptx in Srm
Time and Space Complexity Analysis.pptx
include ltfunctionalgt include ltiteratorgt inclu.pdf
Write a program to find the number of comparisons using the binary se.docx
Oops lab manual2
standard template library(STL) in C++
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Matuura cpp
Sppu University|BE|Computer Engineering|OOPs|unit 6 notes|ppt
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
Object Oriented Programming Using C++: C++ STL Programming.pptx
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Ad

More from Seok-joon Yun (20)

PDF
Retrospective.2020 03
PDF
Sprint & Jira
PPTX
Eks.introduce.v2
PDF
Eks.introduce
PDF
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
PDF
아파트 시세,어쩌다 머신러닝까지
PPTX
Pro typescript.ch07.Exception, Memory, Performance
PPTX
Doing math with python.ch07
PPTX
Doing math with python.ch06
PPTX
Doing math with python.ch05
PPTX
Doing math with python.ch04
PPTX
Doing math with python.ch03
PPTX
Doing mathwithpython.ch02
PPTX
Doing math with python.ch01
PPTX
Pro typescript.ch03.Object Orientation in TypeScript
PDF
C++ Concurrency in Action 9-2 Interrupting threads
PDF
Welcome to Modern C++
PDF
[2015-07-20-윤석준] Oracle 성능 관리 2
PDF
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
PDF
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
Retrospective.2020 03
Sprint & Jira
Eks.introduce.v2
Eks.introduce
AWS DEV DAY SEOUL 2017 Buliding Serverless Web App - 직방 Image Converter
아파트 시세,어쩌다 머신러닝까지
Pro typescript.ch07.Exception, Memory, Performance
Doing math with python.ch07
Doing math with python.ch06
Doing math with python.ch05
Doing math with python.ch04
Doing math with python.ch03
Doing mathwithpython.ch02
Doing math with python.ch01
Pro typescript.ch03.Object Orientation in TypeScript
C++ Concurrency in Action 9-2 Interrupting threads
Welcome to Modern C++
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-10-윤석준] Oracle 성능 관리 & v$sysstat
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
System and Network Administraation Chapter 3
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
top salesforce developer skills in 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Digital Strategies for Manufacturing Companies
PPTX
L1 - Introduction to python Backend.pptx
Softaken Excel to vCard Converter Software.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo POS Development Services by CandidRoot Solutions
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Online Work Permit System for Fast Permit Processing
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
System and Network Administraation Chapter 3
Wondershare Filmora 15 Crack With Activation Key [2025
top salesforce developer skills in 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
How to Migrate SBCGlobal Email to Yahoo Easily
VVF-Customer-Presentation2025-Ver1.9.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 2 - PM Management and IT Context
How to Choose the Right IT Partner for Your Business in Malaysia
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Operating system designcfffgfgggggggvggggggggg
ManageIQ - Sprint 268 Review - Slide Deck
Digital Strategies for Manufacturing Companies
L1 - Introduction to python Backend.pptx

[KOSSA] C++ Programming - 17th Study - STL #3