Raised This Month: $ Target: $400
 0% 

How to order items by price?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-14-2013 , 16:54   Re: How to order items by price?
Reply With Quote #2

Since I'm guessing you have 2 dynamic arrays that stores name and cost ArraySort() is out of the question since it won't match the other array.

You could either make your own sorting function using ArraySwap on both arrays to keep them synced.
Another option is to create a new array that works like a key to both arrays and sort that using 1DCustom.

I can't write it for you since the function you supplied is missing the name array...

EDIT:
Here's the basics of the first method:
Code:
new size = ArraySize(hArray); for ( new i = 1 ; i < size ; i++ ) {     for ( new j = i ; j > 0 ; j-- ) {         if ( ArrayGetCell(hArray, j) < ArrayGetCell(hArray, j - 1) ) { // Use < for ascending and > for descending.             ArraySwap(hArray, j, j - 1);             ArraySwap(hStringArray, j, j - 1);         }         else             break;     } }
__________________

Last edited by Black Rose; 09-14-2013 at 18:11.
Black Rose is offline
 



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 Off

Forum Jump


All times are GMT -4. The time now is 18:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode