954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Sort a MultiDimensional Array

How to Sort a MultiDimensional Array in C ????
in ascending order ?

breal
Newbie Poster
4 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

how many dimensions are we talking about?

two? thwee?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Have you figured out how to sort a 1-D array using your own comparison function, and the standard library qsort() function?

It's exactly the same method, the only trick is getting the compare function declared properly.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
How to Sort a MultiDimensional Array in C ???? in ascending order ?

If your are trying to sort a MultiDimensional array of character you can see this. this is simple bubble sort

#define SIZE 100
void Sort(char arr[SIZE][SIZE], int NoOfRows) {
	int i=0,j=0 ;
	char temp[SIZE] ;
	for(i=0;i<NoOfRows;++i) {
		for(j=0;j<NoOfRows;++j) {
			if(0 > strcmp(arr[i],arr[j])) {
				strcpy(temp,arr[j]) ;
				strcpy(arr[j],arr[i]) ;
				strcpy(arr[i],temp) ;
			}
		}
	}
	return ;
}
dubeyprateek
Junior Poster
176 posts since Mar 2006
Reputation Points: 39
Solved Threads: 24
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You