Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
矩阵排序c++; 我需要在C++中基于特定的列排序矩阵,并且它必须尽可能多地执行。 这是矩阵 JobId;DueDate;RelDate;TardPenalty 1;575;4;1 2;563;70;2 3;483;1;8 4;519;68;1 5;540;64;10 6;546;126;8 7;550;2;6 8;563;70;4 9;470;9;6 10;480;21;3 11;489;6;6 12;593;29;10 13;532;37;7 14;591;25;10 15;468;7;1 16;570;26;1 17;498;73;5 18;504;0;4 19;510;5;10 20;541;15;8 21;583;13;3 22;532;37;3 23;534;42;8 24;585;16;4 25;491;8;5 26;584;66;9 27;563;70;7 28;555;40;3 29;475;65;8 30;549;27;6_C++_Sorting_Matrix - Fatal编程技术网

矩阵排序c++; 我需要在C++中基于特定的列排序矩阵,并且它必须尽可能多地执行。 这是矩阵 JobId;DueDate;RelDate;TardPenalty 1;575;4;1 2;563;70;2 3;483;1;8 4;519;68;1 5;540;64;10 6;546;126;8 7;550;2;6 8;563;70;4 9;470;9;6 10;480;21;3 11;489;6;6 12;593;29;10 13;532;37;7 14;591;25;10 15;468;7;1 16;570;26;1 17;498;73;5 18;504;0;4 19;510;5;10 20;541;15;8 21;583;13;3 22;532;37;3 23;534;42;8 24;585;16;4 25;491;8;5 26;584;66;9 27;563;70;7 28;555;40;3 29;475;65;8 30;549;27;6

矩阵排序c++; 我需要在C++中基于特定的列排序矩阵,并且它必须尽可能多地执行。 这是矩阵 JobId;DueDate;RelDate;TardPenalty 1;575;4;1 2;563;70;2 3;483;1;8 4;519;68;1 5;540;64;10 6;546;126;8 7;550;2;6 8;563;70;4 9;470;9;6 10;480;21;3 11;489;6;6 12;593;29;10 13;532;37;7 14;591;25;10 15;468;7;1 16;570;26;1 17;498;73;5 18;504;0;4 19;510;5;10 20;541;15;8 21;583;13;3 22;532;37;3 23;534;42;8 24;585;16;4 25;491;8;5 26;584;66;9 27;563;70;7 28;555;40;3 29;475;65;8 30;549;27;6,c++,sorting,matrix,C++,Sorting,Matrix,存储在向量Rel[][4] 我需要为DueDate(Rel[][1])对其进行排序,并跟踪其他数据。 有人能帮我吗?我尝试使用sort()函数,但它不适合矩阵 非常感谢 编辑: 我做了一个矩阵快速排序算法,但它崩溃了,这是我的代码 void quickSort(vector<vector<int>> arr, int left, int right) { int i = left, j = right; vector<int> tmp;

存储在
向量Rel[][4]
我需要为DueDate(Rel[][1])对其进行排序,并跟踪其他数据。 有人能帮我吗?我尝试使用sort()函数,但它不适合矩阵

非常感谢

编辑: 我做了一个矩阵快速排序算法,但它崩溃了,这是我的代码

void quickSort(vector<vector<int>> arr, int left, int right) {
    int i = left, j = right;
    vector<int> tmp;
    int pivot = arr[(left + right) / 2][1];

    /* partition */
    while (i <= j) {
        while (arr[i][1] < pivot)
            i++;
        while (arr[j][1] > pivot)
            j--;
        if (i <= j) {
            for (int l = 0; l < 4; l++) {
                tmp[l] = arr[i][l];
            }
            for (int l = 0; l < 4; l++) {
                arr[i][l] = arr[j][l];
            }
            for (int l = 0; l < 4; l++) {
                arr[j][l] = tmp[l];
            }

            i++;
            j--;
        }
    };

    /* recursion */
    if (left < j)
        quickSort(arr, left, j);
    if (i < right)
        quickSort(arr, i, right);
}
void快速排序(向量arr,int left,int right){
int i=左,j=右;
向量tmp;
int pivot=arr[(左+右)/2][1];
/*分割*/
而(我)
j--;

如果(i这看起来不像是一个矩阵。这看起来像一系列记录。我会定义一个记录:

struct Record
{
    int JobId;
    int DueDate;
    int RelDate;
    int TardPenalt
};
将数据存储为

std::vector<Record> Rel;

如果将sortByDate内联,则不太可能做得更好。

是否有vwctors向量数组?如果将矩阵存储为行向量,则为
排序编写自定义比较并不困难。是的,这是行向量,但我不知道如何使用
编写执行排序功能>vector
您已经将性能抛出了窗口。请使用或其他方法。如果问题陈述确定了Rel的格式,则需要向我们显示实际定义。
vector
将不会编译。
bool sortByDate( const Record& lhs, const Record& rhs )
{
    return lhs.DueDate < rhs.DueDate;
}
std::sort( Rel.begin(), Rel.end(), sortByDate );