Raised This Month: $ Target: $400
 0% 

[Solved] Sorting Arrays


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
BhK
Junior Member
Join Date: Dec 2014
Location: India
Old 01-09-2016 , 05:15   [Solved] Sorting Arrays
Reply With Quote #1

I know sorting an array is common and must be known for a beginner, But i am a little confuse here i tried some methods which came in my mind but failed !
Now,
g_Array[10] = {0,5,6,1,9,2,4,6,7,2}
if we sort it in descending order we get
9
7
6
5
...
0
but i want to store their place holders too
g_Holders[10]
4 ( cause it contains 9)
8 ( cause it contains 7)
and so on ...

the method i used to sort array (which i m currently learning in my school),
you can tell me another method too, if its working i would have no problem in using it !

PHP Code:
new g_Array[10] = {0,5,6,1,9,2,4,6,7,2}
new 
g_Temp
server_print
("Array Test")
for(new 
k=1;k<10;k++)
{
    for(new 
j=0;j<(10-k);j++)
    {
        if(
g_Array[j]<g_Array[j+1])
        {
            
g_Temp g_Array[j];
            
g_Array[j] = g_Array[j+1];
            
g_Array[j+1] = g_Temp
        
}
    }
}
for(new 
j=0;j<10;j++)
{
    
server_print("%i",g_Array[j]);

how can i get their place holders ?

Last edited by BhK; 01-18-2016 at 02:02. Reason: Solved
BhK 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 09:25.


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