Sorting 2D Arrays With Recursive Bubble Sort

How can I perform a sort in 2D array of chars using Recursive bubble s

Page 1 of 1

1 Replies - 5475 Views - Last Post: 25 January 2009 - 06:05 PM Rate Topic: ***** 1 Votes

#1 mahdiahmadirad  Icon User is offline

  • New D.I.C Head

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

Sorting 2D Arrays With Recursive Bubble Sort

Posted 25 January 2009 - 12:31 PM

Hi Dears!
I am a Beginner, Please Help Me.
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  Icon User is offline

  • Banned

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

Re: Sorting 2D Arrays With Recursive Bubble Sort

Posted 25 January 2009 - 06:05 PM

http://en.wikipedia....iki/Bubble_sort
http://mathbits.com/...rays/Bubble.htm
http://www.daniweb.c...hread62298.html
http://www.dreaminco.../snippet951.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1