On Mon, 11 Jan 2016 06:01:36 -0800 (PST)
parais...@gmail.com wrote:
> Create your own type embedding a list and Add the sort interface
> methods.
>
> type Foo struct{
> *list.List
> }
>
> func (f *Foo) Reverse(i,j int){ ... }
^^^ I think you rather meant implementing sort.Interface [1].
The problem is that this interface while *in theory* applicable to any
container type which implements indexing, is still targeted for
containers for which index lookup is a O(1) operation, but for linked
lists it's O(N). So I'd say to sort a container/list collection,
some other approach is called for -- like using a temporary supporting
slice which would map collection indexes to elements while sorting.
But this precludes using of the standard mechanisms of the sort package.
Another approach could be just making a slice of (pointers to) elements
in the linked list, sorting them using the sort package and then
creating another linked list off the slice's contents.
1.
https://golang.org/pkg/sort/#Interface