V
V
Vladimir Grabko2016-10-04 09:19:49
go
Vladimir Grabko, 2016-10-04 09:19:49

How to sort in descending order?

I have data

type Unit struct {
  Attack  int32
  Defense int32
  Keep    int64
  Price   int64
}
type Units map[string]Unit

I need to sort map elements in ascending/descending order by any field. What are the algorithms for this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nwton, 2016-10-04
@VGrabko

What a question, such an answer. Classic:
_original

S
Smithson, 2016-10-04
@Smithson

https://www.google.ru/#newwindow=1&q=%D0%B0%D0%BB%...

E
Evgeniy Ivakha, 2016-10-13
@ivahaev

The correct answer is that map elements are not sorted. The keys are always output in random order.
If you need to sort by values, then you need to use slices.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question