|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
|
Does anyone know of a good sort algorithm for a 2D array? the array is 5X15, and the first column is the id number. the only catch is that it is being sorted by the first column, but the last 4 columns must stay with the original id number. so if anyone knows one or knows of a website that has some algoritms on it, that would be greatly appreciated.
thanks ^dan |
|
|
|
|
|
#2 |
|
Member (10 bit)
|
this is what i have got so far by editing a 1d array sort method, but it isnt sorting the last 4 elements correctly. anyone have any thoughts?
int i, j, min, minidx; int temp0, temp1, temp2, temp3, temp4; for(i=0;i<(NumToysTotal - 1);i++){ min=Toy[i][0]; minidx=i; for(j=i+1;j min=Toy[j][0]; minidx=j; } } if(min temp1=Toy[i][1]; temp2=Toy[i][2]; temp3=Toy[i][3]; temp4=Toy[i][4]; Toy[i][0]=min; Toy[minidx][0]=temp0; Toy[minidx][1]=temp1; Toy[minidx][2]=temp2; Toy[minidx][3]=temp3; Toy[minidx][4]=temp4; } } thanks ^dan Last edited by GSXdan; 04-20-2003 at 09:03 PM. |
|
|
|
|
|
#3 |
|
Member (10 bit)
|
finally got it:
int temp0, temp1, temp2, temp3, temp4; for(int i=0;i<(NumToysTotal - 1);i++) { for(int j=1;j if(Toy[j][0] temp0=Toy[j][0]; temp1=Toy[j][1]; temp2=Toy[j][2]; temp3=Toy[j][3]; temp4=Toy[j][4]; Toy[j][0]=Toy[j-1][0]; Toy[j][1]=Toy[j-1][1]; Toy[j][2]=Toy[j-1][2]; Toy[j][3]=Toy[j-1][3]; Toy[j][4]=Toy[j-1][4]; Toy[j-1][0]=temp0; Toy[j-1][1]=temp1; Toy[j-1][2]=temp2; Toy[j-1][3]=temp3; Toy[j-1][4]=temp4; } } } ^dan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|