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

View File

@@ -1,6 +1,6 @@
// even.go
package even
func Even(i int) bool { // exported function
func Even(i int) bool { // exported function
return i%2 == 0
}

View File

@@ -14,19 +14,21 @@ func Fibonacci(n int) (res int) {
func Fibonacci(op string, n int) (res int) {
if n <= 1 {
switch op {
case "+":
res = 1
case "*":
res = 2
default: res = 0
case "+":
res = 1
case "*":
res = 2
default:
res = 0
}
} else {
switch op {
case "+":
res = Fibonacci(op, n-1) + Fibonacci(op, n-2)
case "*":
res = Fibonacci(op, n-1) * Fibonacci(op, n-2)
default: res = 0
case "+":
res = Fibonacci(op, n-1) + Fibonacci(op, n-2)
case "*":
res = Fibonacci(op, n-1) * Fibonacci(op, n-2)
default:
res = 0
}
}
return

View File

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

View File

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

View File

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

View File

@@ -2,12 +2,12 @@
package main
import (
"fmt"
"./even/even"
"fmt"
)
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))
}
}

View File

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