2. basic data structures(1)
-
Upload
hongjun-jang -
Category
Education
-
view
175 -
download
0
Transcript of 2. basic data structures(1)
Basic Data Structures(1)
2016. 3. 19장 홍 준
From abstract, to discrete
A : B, CB : C
Contents• Array
• Tree- Binary- General
• Graph- non-weighted- weighted
Array(Data Type) (Name)[Dim_1_Size]…[Dim_k_Size]
vector < vector < … > > (Name)
Tree - Binary1. Array1) 2*index : left child, 2*index + 1 : right child2) left child : index_p, right child : index_q
2. VectorVector <Type> a[Size];a[from].push_back(to);a[to].push_back(from);
Tree - General1. Linked Listlist <Type> (Name)[Size];
2. Vectorvector <Type> a[Size];
a[from].push_back(to); a[to].push_back(from);list 와 vector 모두 똑같이 사용할 수 있다 .
STL <list> example
STL <vector> example
Graph• 표현법은 트리와 같음 .
• Non-weighted 의 경우 Adjacent Matrix 에 들어가는 value 는 constant
• Weighted 의 경우 , weight.
실습 문제• N 개의 정점 , M 개의 가중치가 있는 간선의 그래프가 있다 .• N, M, M 개의 간선 정보가 주어지면 , 입력을 받고 출력을 하자 .
- input3 41 2 13 4 21 3 23 2 1
- output1 : (2, 1), (3, 2)2 : (1, 1) (3, 1)3 : (1, 2), (2, 1), (4, 2)4 : (3, 2)