본문 바로가기

PROGRAMMING LANGUAGE/C++

(43)
std::map #include #include #include using namespace std; int main() { map mp1; mp1.insert(map::value_type(1,2)); mp1.insert(map::value_type(2, 5)); mp1.insert(map::value_type(3, 7)); mp1[6] = 11; mp1[7] = 21; mp1[3] = 8; mp1[5] = 4; map mp2; mp2[8] = 3; mp2[9] = 10; mp1.insert(mp2.begin(), mp2.end()); for (auto itr = mp1.begin(); itr != mp1.end(); ++itr) { cout first
그래프 알고리즘 (bfs,dfs) #include #include #include using namespace std; bool visited[9]; vector graph[9]; void dfs(int x) { visited[x] = true; cout
이진탐색 #include #define ITEM_SIZE 10 using namespace std; void print_arr(int a[], int size) { for (int i = 0; i < size; i++) { cout
set 사용하기 #include #include using namespace std; int main() { // set 선언 set mySet; set::iterator iter; // set에 값 할당 mySet.insert(90); mySet.insert(80); mySet.insert(70); mySet.insert(60); mySet.insert(50); mySet.insert(90); // for문으로 출력 for (iter = mySet.begin(); iter != mySet.end(); iter++) { cout
map 사용하기 #include #include using namespace std; int main() { // map은 값을 넣으면 자동정렬된다. // map의 구조를 갖는다. map phoneBook; phoneBook["홍길동"] = "01011112222"; phoneBook["일지매"] = "01077778888"; phoneBook["박진수"] = "01045387622"; phoneBook["김박"] = "01099652465"; map::iterator phoneIter; phoneIter = phoneBook.begin(); for (; phoneIter != phoneBook.end(); phoneIter++) { cout
list 사용해보기 #include #include using namespace std; int main() { list list1; list::iterator liter; for (int i = 0; i < 10; i++) { list1.push_back(i); } for (liter = list1.begin(); liter != list1.end(); liter++) { cout
iterator, const iterator, reverse iterator #include #include #include using namespace std; // 오름차순 출력 void PrintVector(vector& v) { vector::iterator iter = v.begin(); for (; iter != v.end(); iter++) { cout
STL vector #include #include #include using namespace std; int main() { vector v = { 1,2,3,4 }; vector::iterator iter; iter = v.begin(); *iter = 10; iter++; *iter = 20; v.push_back(5); for (size_t i = 0; i < v.size(); i++) { cout