Exemplo n.º 1
0
// Returns sorted container's elements using with respect to the passed comparator.
// Does not effect the ordering of elements within the container.
// Uses timsort.
func GetSortedValues(container Interface, comparator utils.Comparator) []interface{} {
	values := container.Values()
	if len(values) < 2 {
		return values
	}
	utils.Sort(values, comparator)
	return values
}
Exemplo n.º 2
0
func SortExample() {
	strings := []interface{}{}                  // []
	strings = append(strings, "d")              // ["d"]
	strings = append(strings, "a")              // ["d","a"]
	strings = append(strings, "b")              // ["d","a",b"
	strings = append(strings, "c")              // ["d","a",b","c"]
	utils.Sort(strings, utils.StringComparator) // ["a","b","c","d"]
}
Exemplo n.º 3
0
// Sort sort values (in-place) using.
func (list *List) Sort(comparator utils.Comparator) {

	if list.size < 2 {
		return
	}

	values := list.Values()
	utils.Sort(values, comparator)

	list.Clear()

	list.Add(values...)

}
Exemplo n.º 4
0
// Sorts values (in-place) using timsort.
func (list *List) Sort(comparator utils.Comparator) {
	if len(list.elements) < 2 {
		return
	}
	utils.Sort(list.elements[:list.size], comparator)
}
Exemplo n.º 5
0
func (a *Array) Sort(comparator utils.Comparator) {
	if len(a.elements) < 2 {
		return
	}
	utils.Sort(a.elements[:a.size], comparator)
}