Sorting an array
hoekay, i have an array that i want to sort from highest to lowest. And in an attempt to do so i ran into 2 questions.
1: why can't i declare an array as such:
Spoiler
2: is this right, and efficient? The wiki was kinda vague.
Spoiler
|
Re: Sorting an array
1. Array sizes have to be constant and cannot be dependent on a variable.
If you need to have a dynamic array size, look into cell arrays. 2. You don't even need that list. Code:
|
Re: Sorting an array
Quote:
2. wouldn't that change the frags for the players? because frags are stored in the cell index that correlates to their playerID, this would rearrange values, but not IDs. I need to keep both numbers together. Though i must say....that return statement gives me a nerd-on. :mrgreen: |
Re: Sorting an array
It doesn't even change the player's frags or even how they are associated.
It just reorders the players array. |
Re: Sorting an array
Quote:
Ordering the players array by frags is a great idea! Thanks, man. What would i do without you? Other than have horribly inefficient code..... Also....does anyone know what kind of sort algorithm they use for these? I'd assume a bubble sort, which would make me want to get friskey with new algorithms, if i ever care enough to do so. EDIT: They use Quicksort. (should have guessed-but i forgot about) which i suppose is the best way to do it in a lower-level language such as pawn. And if i ever figure out an easy way to do objects....i just might write a tree-sort. But objects will be relatively difficult. And even then....i'm sure it'll be way too memory intensive for the people around here....even if it is O(log n) EDIT AGAIN: I figured out a way to do it. structure{[value], [leftIndex], [rightIndex]} done in array format We'll see where this takes us when i get around to coding it.... |
| All times are GMT -4. The time now is 06:06. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.