예전 프로그래밍 방법론 수업에서 배운 것들
자료들을 재정리 해 보았다.
특히 map은 매우 유용할 것 같다.
deque
push.front, push.back, pop.front, pop.back
-list와 비슷해보이나 random access가 가능하고, 중간에 insertion/deletion은 불가능
set/multiset
단일 원소, 오름/내림차순으로 소팅
내부 구현은 tree구조로 되어있음. priority queue 생각
map/multimap
key-value로 값 저장.
cout<< Employees[5235]; //David.D. 사원번호-이름 저장
multimap<string, int> m;
m.insert(pair<string, int>("A",930903));
Reverse Iterator
vector<int>::reverse_iterator p = container.rbegin(); p!= container.rend(); p++
//container.rbegin() == container.end()-1
//container.rend() == container.begin()-1
Filling Algorithms
(1)전체 Fill
vector<int> a(10);
fill(a.begin(),a.end(),1);
(2)n개 Fill
fill_n(a.begin(),n,);
(3)부분 복사
copy(a.begin(),a.begin()+4,b.begin());
(4)전체 랜덤 Fill
generate(a.begin(),a.end(),RandomInt(1,100));
(5)부분 n개 Fill
generate(a.begin(),10,RandomInt(1,100));
Relocating Algorithms
(1)Sort
sort(a.begin(),a.end(),compare);
bool compare(const int& x, const int& y){
return x>y;
}
(2)Reverse
reverse(a.begin(), a.end());
(3)Random_shuffle
random_shuffle(a.begin(),a.end());
Searching Algorithms
(1)최대, 최소값
vector<int>::iterator = max_element(a.begin(), a.end());
vector<int>::iterator = min_element(a.begin(), a.end());
(2)찾기(Linear search)
find(a.begin(), a.end(), 12345);
(3)있는지만 찾기(Binary search)
bool isFound = binary_search(a.begin(), a.end(), 12345);
'[Study] 알고리즘 문제풀이' 카테고리의 다른 글
Union,Find #DisjointSet #1union-by-rank #2path-compression (0) | 2017.05.02 |
---|---|
플루이드 와샬 #All-pairs-shortest-path #Dijkstra (0) | 2017.05.01 |
11404-플로이드 #AllPairsShortestPath #자료구조의소팅 #qsort사용법 (0) | 2017.04.20 |
2174-로봇시뮬레이션 #class내의 static변수 #?:숏코딩 (0) | 2017.04.18 |
14500-테트로미노 #Segmentation Fault #Static (0) | 2017.04.18 |