|
|
@@ -58,7 +58,7 @@ func (t TT) String() string {
|
|
|
t.String()
|
|
|
```
|
|
|
|
|
|
-**练习 10.12** [type_string.go](exercises\chapter_10\type_string.go)
|
|
|
+**练习 10.12** [type_string.go](exercises/chapter_10/type_string.go)
|
|
|
|
|
|
给定结构体类型 `T`:
|
|
|
|
|
|
@@ -72,19 +72,19 @@ type T struct {
|
|
|
|
|
|
值 `t`: `t := &T{7, -2.35, "abc\tdef"}`。给 T 定义 `String()`,使得 `fmt.Printf("%v\n", t)` 输出:`7 / -2.350000 / "abc\tdef"`。
|
|
|
|
|
|
-**练习 10.13** [celsius.go](exercises\chapter_10\celsius.go)
|
|
|
+**练习 10.13** [celsius.go](exercises/chapter_10/celsius.go)
|
|
|
|
|
|
为 `float64` 定义一个别名类型 `Celsius`,并给它定义 `String()`,它输出一个十进制数和 °C 表示的温度值。
|
|
|
|
|
|
-**练习 10.14** [days.go](exercises\chapter_10\days.go)
|
|
|
+**练习 10.14** [days.go](exercises/chapter_10/days.go)
|
|
|
|
|
|
为 `int` 定义一个别名类型 `Day`,定义一个字符串数组它包含一周七天的名字,为类型 `Day` 定义 `String()` 方法,它输出星期几的名字。使用 `iota` 定义一个枚举常量用于表示一周的中每天(MO、TU...)。
|
|
|
|
|
|
-**练习 10.15** [timezones.go](exercises\chapter_10\timezones.go)
|
|
|
+**练习 10.15** [timezones.go](exercises/chapter_10/timezones.go)
|
|
|
|
|
|
为 `int` 定义别名类型 `TZ`,定义一些常量表示时区,比如 UTC,定义一个 `map`,它将时区的缩写映射为它的全称,比如:`UTC -> "Universal Greenwich time"`。为类型 `TZ` 定义 `String()` 方法,它输出时区的全称。
|
|
|
|
|
|
-**练习 10.16** [stack_arr.go](exercises\chapter_10\stack_arr.go) / [stack_struct.go](exercises\chapter_10\stack_struct.go)
|
|
|
+**练习 10.16** [stack_arr.go](exercises/chapter_10/stack_arr.go) / [stack_struct.go](exercises/chapter_10/stack_struct.go)
|
|
|
|
|
|
实现栈 (stack) 数据结构:
|
|
|
|
|
|
@@ -101,9 +101,9 @@ type T struct {
|
|
|
|
|
|
为栈定义一个 `Stack` 类型,并为它定义 `Push` 和 `Pop` 方法,再为它定义 `String()` 方法(用于调试)输出栈的内容,比如:`[0:i] [1:j] [2:k] [3:l]`。
|
|
|
|
|
|
-1)[stack_arr.go](exercises\chapter_10\stack_arr.go):使用长度为 4 的 int 数组作为底层数据结构。
|
|
|
+1)[stack_arr.go](exercises/chapter_10/stack_arr.go):使用长度为 4 的 int 数组作为底层数据结构。
|
|
|
|
|
|
-2) [stack_struct.go](exercises\chapter_10\stack_struct.go):使用包含一个索引和一个 `int` 数组的结构体作为底层数据结构,索引表示第一个空闲的位置。
|
|
|
+2) [stack_struct.go](exercises/chapter_10/stack_struct.go):使用包含一个索引和一个 `int` 数组的结构体作为底层数据结构,索引表示第一个空闲的位置。
|
|
|
|
|
|
3)使用常量 `LIMIT` 代替上面表示元素个数的 4 重新实现上面的 1)和 2),使它们更具有一般性。
|
|
|
|