Example #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
}
Example #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"]
}
Example #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...)

}
Example #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)
}
Example #5
0
func (a *Array) Sort(comparator utils.Comparator) {
	if len(a.elements) < 2 {
		return
	}
	utils.Sort(a.elements[:a.size], comparator)
}