[Solved] Sorting Arrays
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:
|
Re: [Help] Sorting Arrays
You want to get g_array[0]=0 , g_array[1]=1 and so next?
Place number = value number ,yes? |
Re: [Help] Sorting Arrays
g_Array[10] = {0,5,6,1,9,2,4,6,7,2}
//index 0 1 2 3 4 5 6 7 8 9 After sorting g_Array[10] = {9,7,6,6,5,4,2,2,1,0} And i want their index stored in holder like g_Holder[10] = {4,8,2,7,1,6,5,9,3,0} sorry i am not getting a proper word for index! |
Re: [Help] Sorting Arrays
Man, explain what are you trying to do because your methods are uneficient.
Describe what your plugin does. |
Re: [Help] Sorting Arrays
Lets assume
g_Kills[33] when player kills someone it will increment i.e g_Kills[id]++ (id = index) now lets assume that at the end of the round i want to show the players names with maximum kills at the top and minimum kills at the bottom! for doing this it is obvious that we will sort g_Kills[33] ! After sorting it how to get the player index ? if u didnt understand this just show me a way to display players list with maximum kills at the top and minimum kills at the bottom ! |
Re: [Help] Sorting Arrays
Try :
PHP Code:
|
Re: [Help] Sorting Arrays
This is done using a 2-dimension array and SortCustom2D() function. In one dimension you store the player ID and in the other the kills value.
Result: Code:
1. id=1 kills=199PHP Code:
|
Re: [Help] Sorting Arrays
Quote:
Just 1 question why used %d while array is integer. |
Re: [Help] Sorting Arrays
Quote:
|
Re: [Help] Sorting Arrays
%s means string, %d means integer.
Look to ASCII table , find it on google images. For example u have an array g_numbers with g_numbers[0]= 65 Then %d will print 65 but %s will print char value, in ASCII ,65 is 'A'. So %d - 65 %s - A |
| All times are GMT -4. The time now is 09:25. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.