//예시1
int a[10] = {1,2,3,4,5,...,2};
std::sort(a,a+10);
//예시2
bool compare(int a, int b){
return a < b;
}
int a[10] = {2,3,1,...,3};
sort(a,a+10,compare);
//예시3
std::vector<int> v = {1,2,3};
std::sort(v.begin(),v.end());
//내림차순 오름차순
#include <functional>
sort(v.begin(),v.end(),greater<int>()); //내림차순
sort(v.begin(),v.end(),less<int>()); //오름차순
#include <algorithm>
std::binary_search(v.begin(),v.end(), element);
//element가 있다면 true를 반환 없다면 false를 반환
#include <map>
//map 선언하기
map<string, int> m;
//데이터 찾기(search)
if(m.find("Alice") != m.end()){
cout<<"find"<<endl;
} else {
cout<<"not find"<<endl;
}
//map에 데이터 삽입
m.insert({"Cam",300});
//map iterator로 값 추출하기
for(auto map: map){
a = map.second;
b = map.first;
}
//삭제
map.erase(key);
//길이
vector.size();
//선언
std::vector<int> v(갯수, 요소);
Stack
#include <stack>
std::stack<int> s;//선언
s.empty()
s.top()
s.push(element)
s.pop()