<목차>
0. STL 이란?
1. Vector
2. List
3 Stack/Queue
4. Set
5. Map
6. Example: DFS(Depth first search)/깊이 우선 탐색
7. Python code
0.1 STL이란?
STL은 표준 템플릿 라이브러리(STL: Standard Template Library)는 C++을 위한 라이브러리로서 C++ 표준 라이브러리의 많은 부분에 영향을 끼쳤다.
0.2 STL 구성요소
이것은 알고리즘(연산), 컨테이너, 그리고 반복자라고 불리는 세 가지의 구성 요소를 제공한다.
즉, 쉽게 말해서 STL은 C와 C++에 좀 더 쉽게 알고리즘 구현을 위해서 라이브러리를 제공하는 것이라고 생각하면 된다.
#DFS구현
graph = {}
f = open ('graph.txt', 'r')
aline = f.readline()
#n = 버택스의 수 / m = 엣지의 수
n, m = map(int,(aline.split()))
#그래프에 vertex를 저장.
for i in range(n):
graph[i+1] = []
for i in range(m): #그래프에 엣지 저장
aline = f.readline()
n1, n2 = map(int,aline.split(' '))
print(n1,n2)
graph[n1].append(n2)
graph[n2].append(n1)
for i in range(n):
graph[i+1].sort() #정렬
print(graph)
'자료구조와 알고리즘 > 알고리즘(학부과정)' 카테고리의 다른 글
그래프 - Graph(0. Introduction / 1. what is graph?) (0) | 2021.12.07 |
---|---|
4. 그래프 (0) | 2021.11.09 |
분할정복 - Divide and Conquer (3.2 Multiplication) (0) | 2021.10.05 |
분할정복 - Divide and Conquer (3.1 Recurrence relation) (0) | 2021.10.05 |
분할정복 - Divide and Conquer (3.0 Introduction) (0) | 2021.10.04 |