#need help on C++ delete operation

5 messages · Page 1 of 1 (latest)

iron scroll
#

It should should shift to the right after deleting an element from the array like on the first picture, but then i always get a wrong output or result as the row 1: column 2 is always 0.

Code:

// Deletion block that moves the remaining elements to the front if (rowPosition >= 0 && rowPosition < row && columnPosition >= 0 && columnPosition < column) { for (int rowIndex = rowPosition; rowIndex < row; rowIndex++) { for (int columnIndex = (rowIndex == rowPosition ? columnPosition : 0); columnIndex < column - 1; columnIndex++) { array[rowIndex][columnIndex] = array[rowIndex][columnIndex + 1]; } array[rowIndex][column - 1] = 0; // Set the last element to 0 } } else { cout << "Invalid position for deletion." << endl; }

pearl mirageBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

ancient bobcat
#

have you tried stepping through it with a debugger?

iron scroll
#

!solved