You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current List implementation doesn't support sorting. However, it may be needed to have both sorting possibility and constant-time insertion and deletion for some cases. This proposal suggests adding container/list.List.Sort() method to get such.
Mergesort can be used for initial implementation since it's a classical algorithm to sort linked lists. It does stable sort in constant space and O(n*log(n)) time complexity.
I don't have a particular problem with this, but might it make more sense to create a new linked list type (list.ListOf? list.Of?) with generics support and focus development on that one? If this proposal is accepted, it'll get added in Go 1.18 at the same time as generics anyways by the current plan.
Linked lists are bad and should not be used outside of teaching. Deques are good and should be used in nearly every case. IMO, container/list should either be deprecated or it should get a new generic Deque implementation and the documentation should tell users to use that instead of the current List type. Currently, list.List has no Swap(i, j) method because looking up i and j is an O(n) operation. With a deque, it becomes O(1), so you could add Swap and use generic comparables for Less(i, j), but…
If you're sorting your list, you probably actually want a priority queue, which is implemented by container/heap currently. That package should probably be updated for generics by adding some new generic implementation and deprecating the current interface implementation.
The current List implementation doesn't support sorting. However, it may be needed to have both sorting possibility and constant-time insertion and deletion for some cases. This proposal suggests adding
container/list.List.Sort()
method to get such.Mergesort can be used for initial implementation since it's a classical algorithm to sort linked lists. It does stable sort in constant space and O(n*log(n)) time complexity.
This PR can be used as a reference.
The text was updated successfully, but these errors were encountered: