草庐IT

ByDifference

全部标签

go - 如何将排序接口(interface)实现类型作为函数参数传递?

我正在编写不同的调度算法,想比较各种排序作业的方法。我在结构上有一个函数,我想传递排序接口(interface)类型的类型以供函数内的排序使用。typeSchedulestruct{Jobs[]Job}typeByDifference[]Job//ByDifferenceimplementssort.InterfacetypeByRatio[]Job//ByRatioimplementssort.Interfacefunc(s*Schedule)Schedule(OrderBysort.Interface){//Summationvariablesomitted//Thisfailsa

go - 如何将排序接口(interface)实现类型作为函数参数传递?

我正在编写不同的调度算法,想比较各种排序作业的方法。我在结构上有一个函数,我想传递排序接口(interface)类型的类型以供函数内的排序使用。typeSchedulestruct{Jobs[]Job}typeByDifference[]Job//ByDifferenceimplementssort.InterfacetypeByRatio[]Job//ByRatioimplementssort.Interfacefunc(s*Schedule)Schedule(OrderBysort.Interface){//Summationvariablesomitted//Thisfailsa