Raised This Month: $ Target: $400
 0% 

Example code for sorting an array


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 06-15-2004 , 21:04   Example code for sorting an array
Reply With Quote #1

Code:
sort_maps() {     new x,y,z,d     new bool:swap,bool:done,bool:dupe     new temp[32]     for ( x = 0; x < totalmaps; x++ ) {         for ( y = x + 1; y < totalmaps; y++ ) {             swap = false             done = false             dupe = true                     for (z = 0; z < 32; z++) {                 if ( T_LMaps[x][z] != T_LMaps[y][z]) {                     if ( T_LMaps[x][z] > T_LMaps[y][z] && !done) swap = true                     done = true                     dupe = false                 }             }             if (swap) {                 temp = T_LMaps[x]                 T_LMaps[x] = T_LMaps[y]                 T_LMaps[y] = temp             }             else if (dupe) {                 for ( d = y; d < totalmaps; d++ ) {                     T_LMaps[d] = T_LMaps[d + 1]                 }                 y = totalmaps--                 x--             }         }     } }

Just wanted to share since I spent some time on this, dunno if anyone has done thins B4 in one of thier plugins or not.

The array being sorted is T_LMaps
There is also dupe checking in there and it could easily be taken out.

Please let me know if there is any more effecient way of doing this, this was the best I could come up with and it works at least.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
 


Thread Tools
Display Modes

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 14:54.


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