This commit is contained in:
yumaojun03 2026-01-11 10:51:09 +08:00
parent 4cbf3531bc
commit e81fa94b62
5 changed files with 70 additions and 1 deletions

View File

@ -8,3 +8,4 @@
## 课程内容
+ [基础语法与环境搭建](./day01/README.md)
+ [复合数据结构](./day01/README.md)

16
day02/README.md Normal file
View File

@ -0,0 +1,16 @@
# 复合数据结构
之前讲了基础类型接下来讲复合数据结构数组、结构体、切片、Map, 利用基础类型组装起来的类型称为复合数据结构
很多现实的场景 都是复合数据结构,比如:
+ 数组: ip地址 192.168.1.1 就是4个整数的数组
+ 切换(99): 长度不固定的数组, 一堆服务器ip ['192.168.1.1', '192.168.1.1', '192.168.1.1']
+ HashMap(字典, Map): 键值对{'key':'value', 'key':'value'}, 属性不固定的, 服务器{'cpu':'1核', 'mem':'1G', ip: [], ...}
+ 结构体(99): 键值对{'name':'bob', 'age':'18'}, 属性固定的, 服务器{'cpu':'1核', 'mem':'1G', ip: [], ...}
## 课程内容
+ [Go语言数组](./array/README.md)
+ [Go语言切片](./slice/README.md)
+ [Go语言Map](./map/README.md)
+ [Go语言结构体](./struct/README.md)

52
day02/array/README.md Normal file
View File

@ -0,0 +1,52 @@
# 数组
![alt text](image.png)
[课件](https://gitee.com/infraboard/go-course/blob/master/zh-cn/base/array.md)
## 核心概念
根据容器里面数据类型不同,直接分配分配内存(连续的内存地址空间), 内存地址有开始和结束, 访问里面的对象, 我们需要传递索引, (这个索引会根据当前数据结构int8(一个字节) ADDRADDR(+1字节))
由于是连续内存地址, 访问速度极高
+ 长度固定
+ 类型一致(静态语言)
```go
# 数组表示
[]string{}, []int{}, []bool{},
# 特殊情况
[]any{}
```
## 定义数组
![alt text](image-1.png)
1. 数组声明 + 初始化
```go
// 声明数组: [长度]type
var arr [10]int64
// 这个数组的零值是 【0,0,0,0,0,0,0,0,0,0】
// 初始化数组
arr = [10]int64{1,2,3,4,5,6,7,8,9,10}
// 简短方式(声明 + 初始化)
// := 简单声明,
arr := [10]int64{1,2,3,4,5,6,7,8,9,10}
// 动态推算大小 ... => 10, 这种方式不怎么使用
arr := [...]int64{1,2,3,4,5,6,7,8,9,10}
```
2. 赋值: 基础类型的容器,表示多个
```go
// 找到元素(数组里面的插槽), 插槽编号 就是索引(0 - 结束)
arr[0] = 1
arr[1] = 2
arr[2] = 3
```
## 子针数组(重要: 95%)

BIN
day02/array/image-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
day02/array/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB