How to Sort a MultiDimensional Array

Reply

Join Date: Apr 2006
Posts: 4
Reputation: breal is an unknown quantity at this point 
Solved Threads: 0
breal breal is offline Offline
Newbie Poster

How to Sort a MultiDimensional Array

 
0
  #1
May 16th, 2006
How to Sort a MultiDimensional Array in C ????
in ascending order ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: How to Sort a MultiDimensional Array

 
0
  #2
May 16th, 2006
how many dimensions are we talking about?

two? thwee?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: How to Sort a MultiDimensional Array

 
0
  #3
May 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: How to Sort a MultiDimensional Array

 
0
  #4
May 16th, 2006
Originally Posted by breal
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
  1. #define SIZE 100
  2. void Sort(char arr[SIZE][SIZE], int NoOfRows) {
  3. int i=0,j=0 ;
  4. char temp[SIZE] ;
  5. for(i=0;i<NoOfRows;++i) {
  6. for(j=0;j<NoOfRows;++j) {
  7. if(0 > strcmp(arr[i],arr[j])) {
  8. strcpy(temp,arr[j]) ;
  9. strcpy(arr[j],arr[i]) ;
  10. strcpy(arr[i],temp) ;
  11. }
  12. }
  13. }
  14. return ;
  15. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC