Anyone know how to do this? I need to sort a type list by a integer number in the type. Actually its for a purchase list in a strategy game. I'd like the lowest priced items to show up first in the list and the more expensive down the line. I'm sure this is pretty easy, I've just never written a sorting program before.
Sorting Types
Blitz3D Forums/Blitz3D Programming/Sorting Types blitz actually has funcs to do list 'editing', so you can literally just move them without having to copy contents etc.
is a little bubble sort way..not tested, just giving you the gist.
repeat redo=false for play.player each player start.player =after play if start=null exit repeat if start\value<play\value insert start before play ;Will re-arrenge the internal blitz list. reDo=true endif start=after start until start =null next until redo=false
is a little bubble sort way..not tested, just giving you the gist.
Oh yeah, I forgot about the insert commands ... I'm doing it kinda old school.
http://blitzbasic.com/codearcs/codearcs.php?code=1096
Look at those.
By making the array have two elements- one to hold the integer and one to hold the type handle- you can sort the array based on the integer's value and then go through the array and get the type object from the handle.
Just to note, Quicksort is the fastest sorting algorithm in that archive entry.
Look at those.
By making the array have two elements- one to hold the integer and one to hold the type handle- you can sort the array based on the integer's value and then go through the array and get the type object from the handle.
Just to note, Quicksort is the fastest sorting algorithm in that archive entry.