Graph "a".
┌─────A←────┐
│ │ │ 5 vertices: A B C D E
↓ ↓ │
B←───→C────→D 8 edges: A→B A→C B→C C→B
↑ │ C→D D→A D→E E→C
│ ↓
└─────E
Adjacency matrix M has a 1 at M[i;j] if there is an edge from i to j.
A B C D E
┌───────── ⍝ Adjacency matrix for graph "a" above.
A │0 1 1 0 0
B │0 0 1 0 0
C │0 1 0 1 0 ⍝ Third row shows two edges: C→B C→D.
D │1 0 0 0 1
E │0 0 1 0 0
Adjacency vector V is an index vector of all edges from i to i⊃V.
(2 3) (3) (2 4) (1 5) (3) ⍝ Adjacency structure for graph "a".
A B C D E
└───────────── ⍝ Third item shows two edges: 3→(2 4): C→B C→D.
你觉得内存资源管理很麻烦,如出现use after free/double free这种问题。从你的题目里我觉得这个分支的可能性最大,所谓智能指针就是尝试用RAII机制,来解决这种问题的。像shared_ptr(Rc), 通过引用计数托管一块堆内存,等所有持有者销毁后自动释放内存,unique_ptr禁止多个持有者持有引用,避免读写冲突等等。