Sorting 2D arrays in C/C++ in increasing values; knowing the original positon after sorting? -


I have already written a program which is like the 2D array to increase the values.

Here is my input and output

 Input:  

array 2D [0] [0] = 99 arrays 2D [0] [1] = 10 Array 2D [0] [2] = 97 array 2D [0] [3] = 10 arrays 2D [0] [4] = 14 arrows 2D [1] [0] = 73 array 2D [1] [1] = 53 erre 2d [1] [2] = 81 array 2d [1] [3] = 22 array 2d [1] [4] = 88

Aare 2D [0 ] [0] = 10 array 2D [0] [1] = 22 array 2D [0] [2] = 53 error 2D [0] [3] = 53 arrows 2D [0] [4] = 73 Array 2D [1] [0] = 73 Array 2D [1] [1] = 81 Array 2D [1] [2] = 81 Array 2D [1] [3] = 88 Array 2D [1] [4] = 99

Now, what I want to know, is the original condition of the root. Like Array2D is included in [0] [0] 10, but I also want to know where in the input it was 10 before, for example, it was in Array2D [0] [3] in the input, so all of me I want to get the original state of the values.

I do not know how to do it. Maybe use some extra straight to remember the situation or to use pointers.

Note: For sorting, I changed the 2D array in the 1D array, and sort it by using bubble sort and convert it. Back in the 2D array

The simplest way is to have your original Array2D stored in a small structure Do:

  struct {int value; Int position; };  

Before you sort the array that you store the position in the position variable, try something like this for a complete solution:

  strip element {element () {} element (int value): value (value) {} bool operator & lt; (Const element & rhs) const {Return value & lt; Rhs.value;} int value; Int position; }; Element Array 2D [2] [5]; Arrays 2D [0] [0] = 99; Array 2D [0] [1] = 10; Array 2D [0] [2] = 97; Arrays 2D [0] [3] = 10; Array 2D [0] [4] = 14; Array 2D [1] [0] = 73; Array 2D [1] [1] = 53; Array 2D [1] [2] = 81; Array 2D [1] [3] = 22; Array 2D [1] [4] = 88; Int elementCount = sizeof (Array2D) / sizeof (alignment); For (int i = 0; i  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -