В этом коде (C++), я пытаюсь переместить указатель, который указывает на одну «строку» 2D-массива, на следующую строку, вице-верку со следующей строкой. поэтому я попробовал этот код:выражение должно быть модифицируемым значением l 2D с массивами 2D
void bubleSort(char mat[][WORDS]) {
for (int i = LETTERS; i >= 0; i--) {
int position = 0; //This variable is used to move forward in case of same previous letters
for (int j = 1; j < i; j++) {
if (mat[j][position] < mat[j - 1][position]) { //If the words are not sorted according to alphabetic order,
mat[j]--; //swap the poniters of the rows of their letters positions,
mat[j - 1]++;
position = 0; //and initilize 'position' for the next words check.
}
else if (mat[j][position] == mat[j - 1][position]) { //If current position of letter have the same letters,
position++; //jump to next position,
j = ((position < LETTERS - 1) ? j - 1 : i); //and move 'j' back to recheck the words.
}
else position = 0; //if thoose words stay in their place, initilize 'position' for next checking
}
}
}
Тогда говорит составитель «выражение должно быть изменяемой именующим» об этих строках:
mat[j]--; //swap the poniters of the rows of their letters positions,
mat[j - 1]++;
Как мне это исправить?
спасибо.
Вы не можете увеличивать массивы, потому что массивы не указатели. – fredoverflow
С 'std :: vector v;' вы можете просто выполнить 'std :: sort (v.begin(), v.end());'. –
Jarod42
Кстати, вы можете использовать 'std :: swap (mat [j], mat [j - 1])'. – Jarod42