Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,429 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,902 people online right now. Registration is fast and FREE... Join Now!




bubble sort a two dimensional array

 
Reply to this topicStart new topic

bubble sort a two dimensional array, bubble sort

hesse
25 Jan, 2008 - 02:19 AM
Post #1

New D.I.C Head
*

Joined: 25 Jan, 2008
Posts: 1

CODE
#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
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Bubble Sort A Two Dimensional Array
25 Jan, 2008 - 02:40 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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/
User is offlineProfile CardPM
+Quote Post

rockey
RE: Bubble Sort A Two Dimensional Array
26 Jan, 2008 - 03:29 AM
Post #3

D.I.C Head
**

Joined: 2 Jan, 2008
Posts: 57


My Contributions
What error is occur??

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 04:54AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month