# Sorting two dimensional arrays

This is a discussion on Sorting two dimensional arrays within the C Programming forums, part of the General Programming Boards category; Hello, i want to write a programme which will sort two dimensional arrays, from a[0][] to a[2][] ascending and a[3][] ...

1. ## Sorting two dimensional arrays

Hello, i want to write a programme which will sort two dimensional arrays, from a[0][] to a[2][] ascending and a[3][] to a[5][] descending. My code is below but there is a mistake on output and i couldn't figure it out, thanks in advance..

Code:
```#include <stdio.h>
#define row 6
#define col 6
void bubbleSort(int[row][col],int,int,char);

int main()
{
int a[row][col]={{3,4,2,1,0,-1},{5,9,4,-5,-8,7},{8,2,6,5,1,0},{1,5,6,8,0,4},{-6,-9,-4,5,8,-7},{-8,-2,6,-5,1,0}},i,y;
char dec='a';
bubbleSort(a,1,3,dec);
dec='d';
bubbleSort(a,4,6,dec);
for(i=0;i<6;i++)
{
for(y=0;y<col;y++)
{
printf("a[%d][%d]=%d\n",i,y,a[i][y]);
}
}
system("Pause");
return 0;

}

void bubbleSort(int x[row][col],int low,int high,char asc)
{
int i,y,temp,a;
for(i=low-1;i<high;i++)
{
for(a=0;a<6;a++)
{
for(y=0;y<col;y++)
{
if(asc=='a')
{
if(x[i][y]>x[i][y+1])
{
temp=x[i][y+1];
x[i][y+1]=x[i][y];
x[i][y]=temp;
}
}
if(asc=='d')
{
if(x[i][y]<x[i][y+1])
{
temp=x[i][y+1];
x[i][y+1]=x[i][y];
x[i][y]=temp;
}
}
}
}
}
}```

2. What exactly is wrong with the output? :x

3. In output, the values are wrong.. For example a[2][] has only one 1 but in output it gives two 1 and it passes 8, like it in other arrays too...

4. EDIT: ignore me, post was in error

5. Transpose the matrix.
Sort each half of the rows like you want.
Transpose it back to the original orientation.

I think that's what you want.

6. Finally i found, thanks for your replies..