Golang in the Sort Pack sort.search () use tutorial

Source: Internet
Author: User
Tags builtin

Sort()when using the function in the sort package
Cannot use c.ring (Type []uint32) as type sort. Interface in argument to sort. Sort:
[]uint32 does not implement sort. Interface (missing Len method)

cannot use c.ring (type []uint32) as type sort.Interface in argument to sort.Sort:        []uint32 does not implement sort.Interface (missing Len method)

The reason is sort. The definition of Sort () is as follows

func Sort(data Interface)
type Interface interface {    // Len方法返回集合中的元素个数    Len() [int](https://studygolang.com/static/pkgdoc/pkg/builtin.htm#int)    // Less方法报告索引i的元素是否比索引j的元素小    Less(i, j [int](https://studygolang.com/static/pkgdoc/pkg/builtin.htm#int)) [bool](https://studygolang.com/static/pkgdoc/pkg/builtin.htm#bool)    // Swap方法交换索引i和j的两个元素    Swap(i, j [int](https://studygolang.com/static/pkgdoc/pkg/builtin.htm#int))}一个满足sort.Interface接口的(集合)类型可以被本包的函数进行排序。方法要求集合中的元素可以被整数索引
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.