# Sorting 2D Arrays With Recursive Bubble Sort

Page 1 of 1

## 1 Replies - 7676 Views - Last Post: 25 January 2009 - 06:05 PMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=82722&amp;s=3a75840c2020568b6d2534f1ee7c053e&md5check=' + ipb.vars['secure_hash'], cur_rating: 5, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 3
• Joined: 29-November 07

# Sorting 2D Arrays With Recursive Bubble Sort

Posted 25 January 2009 - 12:31 PM

Hi Dears!
If you Can Help me to find out how to sort a 2d arrays of characters with recursive bubble sort algorithm.
I have got something but it doesn't work.
what is my mistake?

I Did codes below So far, but it isn't completed and has some errors. it is my primary Idea. check it and learn me:
```#include <iostream.h>
#include <stdio.h>
#include <string.h>
#define number 3
#define length 3

static char student[number][length];
int i,j,k,NF_Length=15,n;
bool done;
void BubbleSort(void);
bool BubbleUp(int);

void main(){
for(i=0;i<number;i++)
for(j=0;j<length;j++)
cin>>student[i][j];

BubbleSort();

for(i=0;i<number;i++)
for(j=0;j<length;j++)
cout<<student[i][j];
getchar();
}
void BubbleSort(void){

if (number < 2)   // array must be sorted
return;

done = BubbleUp(number);
if (!done){						 // then bubblesort the rest
--number;
BubbleSort();
}
}
bool BubbleUp(int n){
char Temp[35];
done = true;   // until we know better
for (k = 0; k < NF_Length - 1; k++){
if (strcmp(student[n][k],student[n][k+1])>0)
{
done = false;   // because we are making a swap
//Now Swapping
strcpy(Temp,student[n]);
strcpy(student[n],student[n+1]);
strcpy(student[n+1],Temp);
}
}
return done;
}
```

Is This A Good Question/Topic? 0

## Replies To: Sorting 2D Arrays With Recursive Bubble Sort

### #2 Hyper

• Banned

Reputation: 108
• Posts: 2,129
• Joined: 15-October 08

## Re: Sorting 2D Arrays With Recursive Bubble Sort

Posted 25 January 2009 - 06:05 PM