Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-20-2003, 01:17 PM   #1
Member (10 bit)
 
GSXdan's Avatar
 
Join Date: Jun 2002
Location: P-burg, Ohio, USA
Posts: 555
Send a message via AIM to GSXdan
Question 2D array sort algorithm

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
GSXdan is offline   Reply With Quote
Old 04-20-2003, 08:56 PM   #2
Member (10 bit)
 
GSXdan's Avatar
 
Join Date: Jun 2002
Location: P-burg, Ohio, USA
Posts: 555
Send a message via AIM to GSXdan
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 if(Toy[j][0] < min){
min=Toy[j][0];
minidx=j;
}
}

if(min temp0=Toy[i][0];
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.
GSXdan is offline   Reply With Quote
Old 04-21-2003, 09:17 AM   #3
Member (10 bit)
 
GSXdan's Avatar
 
Join Date: Jun 2002
Location: P-burg, Ohio, USA
Posts: 555
Send a message via AIM to GSXdan
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
GSXdan is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:57 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2