So i need to change Element (a integer) from column which is closest to that column average number. For example:
We have this 2D array array[3][3]
1 4 7
2 5 8
3 6 9
So from first column i would need to change/replace 2 ((1+2+3)/3=2) Because it is closest to average of column
For second column i would need to change/replace 5 ((4+5+6)/3=5)
For third 8
so in final version i would get
1 4 7
3 6 9
I "remove" element just by shortening the lenght of array and pushing numbers per 1 slot, here is how i do it for one-dimensional array
int search(char A[], int B[], int n, char tp, int dd) //Search for number
{
int ind = -1;
for (int i = 0; i < n; i++)
if ((A[i] == tp) && (B[i] == dd))
ind = i;
return ind;
}
void remove(char A[], int B[], int & n, int ind) //remove number from array
{
for (int i = ind; i < n - 1; i++)
{
A[i] = A[i + 1];
B[i] = B[i + 1];
}
n--;
I know how to remove elements in simple 1d array, but cant really come up with way of implementing to remove elements from 2d array
Any help would be appreciated
std::vector?std::vector<std::vector<int>>representation of the 2D array in your code.int array[3][3]or somestd::vector<std::vector<int>>container?nitems in size.