fix: coding style and file format for chapter 9.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:30:01 +08:00
parent d9041c7fc3
commit cee64d1429
8 changed files with 207 additions and 205 deletions

View File

@@ -2,8 +2,8 @@
package main package main
import ( import (
"fmt"
"container/list" "container/list"
"fmt"
) )
func main() { func main() {
@@ -17,6 +17,7 @@ func main() {
fmt.Println(e.Value) fmt.Println(e.Value)
} }
} }
/* Example output: /* Example output:
&{0x12542bc0 <nil> 0x12547590 1} &{0x12542bc0 <nil> 0x12547590 1}
&{0x12542ba0 0x12542be0 0x12547590 2} &{0x12542ba0 0x12542be0 0x12547590 2}

View File

@@ -18,7 +18,8 @@ func Fibonacci(op string, n int) (res int) {
res = 1 res = 1
case "*": case "*":
res = 2 res = 2
default: res = 0 default:
res = 0
} }
} else { } else {
switch op { switch op {
@@ -26,7 +27,8 @@ func Fibonacci(op string, n int) (res int) {
res = Fibonacci(op, n-1) + Fibonacci(op, n-2) res = Fibonacci(op, n-1) + Fibonacci(op, n-2)
case "*": case "*":
res = Fibonacci(op, n-1) * Fibonacci(op, n-2) res = Fibonacci(op, n-1) * Fibonacci(op, n-2)
default: res = 0 default:
res = 0
} }
} }
return return

View File

@@ -6,7 +6,7 @@ func GoodDay(name string) string {
return "Good Day " + name return "Good Day " + name
} }
func GoodNight(name string) string{ func GoodNight(name string) string {
return "Good Night " + name return "Good Night " + name
} }
@@ -24,4 +24,3 @@ func IsEvening() bool {
localTime := time.Now() localTime := time.Now()
return localTime.Hour() <= 22 return localTime.Hour() <= 22
} }

View File

@@ -1,8 +1,8 @@
package main package main
import ( import (
"fmt"
"./fibo/fibo" "./fibo/fibo"
"fmt"
) )
var nextFibo int var nextFibo int
@@ -40,6 +40,7 @@ func next() {
result = fibo.Fibonacci(op, nextFibo) result = fibo.Fibonacci(op, nextFibo)
fmt.Printf("fibonacci(%d) is: %d\n", nextFibo, result) fmt.Printf("fibonacci(%d) is: %d\n", nextFibo, result)
} }
/* ***************************************************************** /* *****************************************************************
Output is: Output is:
fibonacci(1) is: 1 fibonacci(1) is: 1
@@ -58,5 +59,3 @@ fibonacci(3) is: 8
... ...
fibonacci(4) is: 32 fibonacci(4) is: 32
********************************************************************/ ********************************************************************/

View File

@@ -1,8 +1,8 @@
package main package main
import ( import (
"fmt"
"./greetings/greetings" "./greetings/greetings"
"fmt"
) )
func main() { func main() {
@@ -12,9 +12,9 @@ func main() {
if greetings.IsAM() { if greetings.IsAM() {
fmt.Println("Good morning", name) fmt.Println("Good morning", name)
} else if greetings.IsAfternoon(){ } else if greetings.IsAfternoon() {
fmt.Println("Good afternoon", name) fmt.Println("Good afternoon", name)
} else if greetings.IsEvening(){ } else if greetings.IsEvening() {
fmt.Println("Good evening", name) fmt.Println("Good evening", name)
} else { } else {
fmt.Println("Good night", name) fmt.Println("Good night", name)

View File

@@ -2,12 +2,12 @@
package main package main
import ( import (
"fmt"
"./even/even" "./even/even"
"fmt"
) )
func main() { func main() {
for i:=0; i<=100; i++ { for i := 0; i <= 100; i++ {
fmt.Printf("Is the integer %d even? %v\n", i, even.Even(i)) fmt.Printf("Is the integer %d even? %v\n", i, even.Even(i))
} }
} }

View File

@@ -11,4 +11,5 @@ func main() {
size := unsafe.Sizeof(i) size := unsafe.Sizeof(i)
fmt.Println("The size of an int is: ", size) fmt.Println("The size of an int is: ", size)
} }
// The size of an int is: 4 // The size of an int is: 4