Skip to content

Commit 40c1b16

Browse files
committed
修正目录
2 parents eaa461a + 87de2f5 commit 40c1b16

File tree

8 files changed

+74
-160
lines changed

8 files changed

+74
-160
lines changed

02-数据结构/01-数组.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## 一 数组概念
2+
3+
数组是最简单的数据结构之一,基本所有的语言都提供了数组,这里只是对数组做出简单的介绍。
4+
5+
## 二 数组的增删改查
6+
7+
## 三 稀疏数组
8+
9+
#### 3.1 问题的引入
10+
11+
如下所示的五子棋程序,有存盘退出和续上盘的功能:
12+
![](../images/Algorithm/sparsearry-1.png)
13+
14+
15+
如果使用二维数组来存储,就会如右侧所示存储很多为0的浪费空间。
16+
17+
#### 3.2 稀疏数组存储数据
18+
19+
当一个数组中大部分元素为0,或者为同一个值的数组时,可以使用稀疏数组来保存该数组,其处理方式为:
20+
- 记录数组一共有几行几列,有多少个不同的值
21+
- 把具有不同值的元素的行列/值记录在一个小规模数组中
22+
23+
如图所示:
24+
![](../images/Algorithm/sparsearry-2.png)
25+
26+
图中的row/,col,val分别代表有多少行,多少列,对应值,其中第一条数据6,7,10存储了左侧数据总计有6行,7列,10个不同值。
27+
28+
#### 3.3 原始数组转换为稀疏数组
29+
30+

images/Algorithm/sparsearry-1.png

77.7 KB
Loading

images/Algorithm/sparsearry-2.png

46 KB
Loading

sources/go/array/SparseArray.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package array
2+
3+
type Node struct {
4+
row int
5+
col int
6+
val interface{}
7+
}
8+
9+
func NewSparseArray(row int, col int) []Node{
10+
var sa []Node
11+
n := Node{
12+
row: row,
13+
col: col,
14+
val: nil,
15+
}
16+
sa = append(sa, n)
17+
return sa
18+
}
19+
20+
// 普通数组转换稀疏数组
21+
22+
23+
// 稀疏数组转普通数组

sources/go/main.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ package main
22

33
import (
44
"fmt"
5+
"algorithm/array"
6+
"algorithm/list"
57
)
68

79

810
func main() {
9-
// sl := list.NewSequenList(10)
10-
// sl.Show()
11-
// sl.Append(15)
12-
// sl.Append(17)
13-
// sl.Append(19)
14-
// sl.Show()
15-
16-
s1 := []int {1,2,3,4,5}
17-
// s2 := []int {6,7,8,9,10}
18-
s2 := append(s1[0:2],s1[0:3])
1911
}

sources/go/queue/CirQueue.go

Whitespace-only changes.

sources/go/queue/SeqQueue.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package queue
2+
3+
// 顺序结构存储队列
4+
type SeqQueue struct {
5+
Size int
6+
Length int
7+
Data []interface{}
8+
Front int // 表示指向队列队首
9+
Rear int // 表示指向队列尾部
10+
}
11+
12+
func NewSeQueue(size int) {
13+
return &SeqQueue{
14+
size,
15+
16+
}
17+
}
18+
19+
// 向队列添加数据

sources/javascript/tree/BinaryTree.js

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)