Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "sort"
- )
- type myIntMap map[int]string
- func (m myIntMap) sort() (index []int) {
- for k, _ := range m {
- index = append(index, k)
- }
- sort.Ints(index)
- return
- }
- type myStringMap map[string]string
- func (m myStringMap) sort() (index []string) {
- for k, _ := range m {
- index = append(index, k)
- }
- sort.Strings(index)
- return
- }
- func main() {
- mim := myIntMap{
- 1: "one",
- 11: "eleven",
- 3: "three",
- }
- for _, k := range mim.sort() {
- fmt.Println(mim[k])
- }
- msm := myStringMap{
- "b": "two",
- "s": "twenty",
- "e": "five",
- }
- for _, k := range msm.sort() {
- fmt.Println(msm[k])
- }
- }
Add Comment
Please, Sign In to add comment