Forum

Quake C sort?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Quake C sort?

Postby DieparBaby » Mon Dec 18, 2006 4:10 pm

As an example, I'd like to sort a set of entities with the classname "player" by their .frags field and then print out at least some of the list to each client. It doesn't seem possible but maybe someone smarter has written a sort function in quake c. Anyone know?

Thanks,
DieparBaby
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh

Postby Spike » Mon Dec 18, 2006 7:42 pm

An insertion sort is probably best.

First, build a chain of them, then while there are still ents in that chain find the highest score and copy it over to a new chain and remove them from the old, inserting at the end of the new chain.
The new chain will then be sorted.

You can then loop through the new chain and print them as you go.
There are no builtins or anything to do this for you.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby DieparBaby » Mon Dec 18, 2006 8:26 pm

Thank you Spike.
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest