Recently I found a competitive programming question that need to add merge sort for 2d array arr[i][j].
row and column count i & j get from user input.
It isn't a good solution if you have input lower row count(assume I && J < 100). But it getting a big integer. Insertion sort is not that good. So I hope to add merge sort instead of that. Specialty is that two of columns needs to be sorted out also
A 2D array which has two columns. How can I implement it more efficiently? It is costly to swap two values when the rows are getting higher and higher. Is there a way to implement it easily.
Here is my insertion sort implementation.
insertionSortA(Cq,globalC);
for(int i =0;i<globalC-1;i++){
for(int j =0;j<globalC-i-1;j++){
if(Cq[j][1]>Cq[j+1][1]){
// swapping
my_temp = Cq[j][1];
Cq[j][1] = Cq[j+1][1];
Cq[j+1][1] = my_temp;
my_temp2 = Cq[j][0];
Cq[j][0] = Cq[j+1][0];
Cq[j+1][0] = my_temp2;
}
}
}
This is only a simple code to demonstrate the idea
If you have anything special ideas. Please put an answer. Thanks in advance.