golang about 05_hash_tables (#42)
* recursion_Golang * go_fmt * selection_sort_Golang * rm-golang * selection_sort_Golang * selection_sort_Golang * selection_sort_Golang * dynamic_golang * golang 05_hash_tables 02_check_voter.go * golang 05_hash_tables 01_price_of_groceries
This commit is contained in:
committed by
Aditya Bhargava
parent
542f4ab0a0
commit
24b6376d94
13
05_hash_tables/golang/01_price_of_groceries.go
Normal file
13
05_hash_tables/golang/01_price_of_groceries.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var book map[string]float64
|
||||
|
||||
func main() {
|
||||
book = make(map[string]float64)
|
||||
book["apple"] = 0.67
|
||||
book["milk"] = 1.49
|
||||
book["avocado"] = 1.49
|
||||
fmt.Println(book)
|
||||
}
|
||||
21
05_hash_tables/golang/02_check_voter.go
Normal file
21
05_hash_tables/golang/02_check_voter.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var voted map[string]bool
|
||||
|
||||
func main() {
|
||||
voted = make(map[string]bool)
|
||||
check_voter("tom")
|
||||
check_voter("mike")
|
||||
check_voter("mike")
|
||||
}
|
||||
|
||||
func check_voter(name string) {
|
||||
if voted[name] {
|
||||
fmt.Println("kick tem out!")
|
||||
} else {
|
||||
voted[name] = true
|
||||
fmt.Println("let tem vote!")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user