排序浮动指针阵列

Sorting floating Pointer array

本文关键字:阵列 指针 排序      更新时间:2023-10-16

我们有:

 private void function(ptr* data, const int size_of_data){
       std::sort(std::begin(data), std::end(data), floatcomparer);

这实际上是可能的吗?还有另一种方法吗?因为我到达这里error: no instance of overloaded function ""std::begin" matches the argument types are: (float *).我知道我们需要像STD使用一样快速排序算法的大小,而PTR*则没有提供随附的尺寸。但是不应该有一种方法,因为我知道我指向的数组有多大?

您的函数签名是错误的,并且您的命令不正确地调用std::sort,您想要更类似的东西:

void function(float* data, std::size_t size_of_data) {
    std::sort(data, data + size_of_size, std::less<float>());
}
std::sort(arr, arr+ size, std::greater<float>());

在哪里可以在此形式中使用通过float arr

func(float[],int sz){...}

使用此比较器可以对其进行排序。