Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "github.com/fighterlyt/permutation"
  6. "reflect"
  7. )
  8.  
  9. type Phone struct {
  10. ID int
  11. Vendor string
  12. }
  13.  
  14. func main() {
  15. phone := []Phone{
  16. Phone{1, "Samsung"},
  17. Phone{2, "HTC"},
  18. Phone{3, "LG"},
  19. Phone{4, "Sony"},
  20. }
  21.  
  22. perm, _ := permutation.NewPerm(phone, func(i, j interface{}) bool {
  23. return reflect.ValueOf(i).FieldByName("ID").Int() < reflect.ValueOf(j).FieldByName("ID").Int()
  24. })
  25.  
  26. for elem, err := perm.Next(); err == nil; elem, err = perm.Next() {
  27. fmt.Println(elem, perm.Left())
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement