# bubble sort a two dimensional array

Page 1 of 1

## 2 Replies - 39300 Views - Last Post: 26 January 2008 - 04:29 AMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=41708&amp;s=ab1e4ce918e0c276733ae12239db8520&md5check=' + ipb.vars['secure_hash'], cur_rating: 5, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hesse

Reputation: 0
• Posts: 1
• Joined: 25-January 08

# bubble sort a two dimensional array

Posted 25 January 2008 - 03:19 AM

```#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX 10
#define MIN 5

/*function prototype*/
void initializeArray(int[][MAX]);
void printArray(int [][MAX]);
void populateRandomValues (int [][MAX],int, int);
void bubblesort(int [][MAX], int,int);

void main(void)
{
int array[MIN][MAX], temp, max, key;
int lower, upper= MAX*10;
initializeArray (array);
printArray (array);
populateRandomValues (array, lower, upper);
printArray (array);
bubblesort(array, temp,max);
printArray (array);
}

void printArray(int array[][MAX])
{
int r, c;
for(r=0;r<MIN;r++)
{
for(c=0;c<MAX;c++)
{
printf(" %d",array[r][c]);
}
printf("\n");
}
printf("\n");
}

void populateRandomValues (int array[][MAX],int lower, int upper)
{
int r,c;
srand(time(NULL));
for(r=0;r<MIN;r++)
{
for(c=0;c<MAX;c++)
{
array[r][c]=1+(rand()%100);
}
}
}void bubblesort(int array[][MAX], int temp,int max)
{
int r,k,c,z;
for(r=0;r<MAX;r++)
{
for(c=0;c<MAX-1;c++)
{
if(array[z][c] > array[z][c+1])
{
temp= array[z][c];
array[z][c]= array[z][c+1];
array[z][c+1]= temp;
}
if(c % (MAX-2) == 0)
{
for(z=0;z<MAX;z++)
{
if(array[r][c]>array[r+1][z])
{
temp = array[r][c];
array[r][c] = array[r+1][z];
array[r+1][z] = temp;
}
}
}
}
}
}
```

* mod edit - added code tags

Is This A Good Question/Topic? 0

## Replies To: bubble sort a two dimensional array

### #2 PennyBoki

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• Joined: 11-December 06

## Re: bubble sort a two dimensional array

Posted 25 January 2008 - 03:40 AM

Hi hesse, welcome, maybe you want to post this as a snippet?
If so make sure the code meets the requirements for submitting a snippet and post it here:

http://www.dreamincode.net/code/

### #3 rockey

Reputation: 1
• Posts: 57
• Joined: 02-January 08

## Re: bubble sort a two dimensional array

Posted 26 January 2008 - 04:29 AM

What error is occur??