How to Sort 2D array with out 1D array Hello I am a new Computer Science student 
Ok, so I am trying to sort the 2D array I know you can actually sort a 2D array by copying it into a 1D array sort it using any Algorithm, and then place back into the 2D array but here is the problem aren't we using more space and time because we have to copy the array back.
What I have tried so far
#include&lt;stdio.h&gt;

#include&lt;stdlib.h&gt;
#include&lt;time.h&gt;

#define ROWS 3
#define COL 5

void sort(int array[], int size);
void random(int rows, int col, int array[][col]);
void print(int rows, int col, int array[][col]);

int main(void)
{
    int set = ROWS*COL;
    int array[ROWS][COL];
    random(ROWS, COL, array);
    print(ROWS, COL, array);
    sort(array[0], set);
    printf(&quot;\n\n\n&quot;);
    print(ROWS, COL, array);
    return 0;
            
}
void print(int rows, int col, int array[][col])
{
    int idx, kdx;
    
    for(idx = 0; idx &lt; rows; idx++)
    {
        for(kdx = 0; kdx &lt; col; kdx++)
        {
            printf(&quot;%d &quot;, array[idx][kdx]);
        }
        printf(&quot;\n&quot;);
    }
}
void random(int rows, int col, int array[][col])
{
    int idx, kdx;
    
    for(idx = 0; idx &lt; rows; idx++)
    {
        for(kdx = 0; kdx &lt; col; kdx++)
        {
            array[idx][kdx] = rand() % 10;
        }
    }
}
void sort(int array[], int size)
{
    int temp, idx, kdx;
    for(idx = 0; idx &lt; size; idx++)
    {
        for(kdx = 0; kdx &lt; size; kdx++)
        {
            if(array[kdx] &gt; array[kdx+1])
            {
                temp = array[kdx + 1];
                array[kdx + 1] = array[kdx];
                array[kdx] = temp;
            }
        }
    }
}
 

But it's not any kind of algorithm and it will not work with dynamic memory you can say since it is just taking benefit of the way c store arrays. But things are different for dynamic arrays in c
Is there any Algorithm to sort 2D array.
By dynamic I presume you mean either:
int* array = malloc(sizeof(int)*col*rows);
or
int* array = new int[rows][col]();
In which case its fairly simple:
void sort(int* array, int size)
{
    int temp, idx, kdx;
    for(idx = 0; idx &lt; size; idx++)
    {
        for(kdx = 0; kdx &lt; size; kdx++)
        {
            if(array[kdx] &gt; array[kdx+1])
            {
                temp = array[kdx + 1];
                array[kdx + 1] = array[kdx];
                array[kdx] = temp;
            }
        }
    }
}

//in main or wherever
int* array = malloc(sizeof(int)*col*rows);
random(array, col*rows);
sort(array, col*rows);
free(array);

Although that is a very sloooooowwwwww sorting operation. How about researching logsort or quicksort?