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

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

how many dimensions are we talking about?

two? thwee?

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.

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 ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.