Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Array values re-position

Author
Message
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 5th May 2010 18:03
Hi guys,
did anyone have done repositioning of items in array?
I wanted to put new value in the array and everything to the end of the array to move one position, but i get confused how to do it exactly.I need this for highscore table.Some ideas how can be done?

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 5th May 2010 19:29
You might would want to learn some sorting methods.

Here is a quick list of algorithms you can look up. Top to bottom is easiest to learn to hardest. The harder ones are MUCH faster than the easier ones.

Bubble sort
Selection sort
Comb sort
Quicksort
Radix sort

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th May 2010 21:05
You could simply carry out a single run of a bubblesort to get the item in place - no need really for a full-blown sort routine.



Or, you could simply say 'stuff it' and use the sort built into my plug-ins, which is simpler still:


luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 5th May 2010 23:43 Edited at: 6th May 2010 00:05
Oh so it wasn`t as complicated as i think.

Sometimes i`m very stupid because i make a frame but look only arround it and can`t see the picture.What i did not think about is that i really do not need the lowest value if the new one is bigger than it, so i can remove it.Next is easy with matrix1 sort command.

Thank you both for this.Thank you IanM for the matrix1 plugin.It makes my life easy.

About the sort ways i managed to find only few Bubble sort related threads.

EDIT: To IanM
I just tried the 2 ways and the first one strangely works sometime but most of the time produce silent crash.

The second way did not work with UDT arrays.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th May 2010 01:16
Here's another thread I found on this a while back, it might be helpful :
http://forum.thegamecreators.com/?m=forum_view&t=71251&b=1
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th May 2010 15:43
Quote: "The second way did not work with UDT arrays."

No, for UDT arrays you need to use SORT ARRAY, and specify the field number you wish to sort by as a negative number.

SORT ARRAY

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 7th May 2010 01:38 Edited at: 7th May 2010 11:05
Something wierd happend, it continues to crash with this part:


Am i using it wrong?
I`m pretty sure this part is enough to show what is wrong, i can provide more code if this is not good.

EDIT: I get everything working.
There was something left behind, the "exit" comand and the sorting can`t do the array properly from given range, but the whole one.So everywhere i was using "for blabla = 1 to max_value", which is 10, i made to "blabla = 0 to max_value" + decreased max_value to 9.This was causing silent crash, because i didn`t get 0 position in the counts.There was some minor adjustment with one offset variable calculation too, it was based to max_value...

Thanks a lot to everybody!Thanks IanM!

There is the thread with the whole stuff:
http://forum.thegamecreators.com/?m=forum_view&t=169546&b=6&p=0

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th May 2010 15:13
You could also have used the SORT ARRAY RANGE command to sort items from 1 to max_value instead

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 7th May 2010 18:37
lol i really should swim throught your plugin commands
Thank you again!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 8th May 2010 05:31
what sort of sort algorithm is used in your sort algorithm, IanM?


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th May 2010 13:33
It's an Introsort by default (quicksort with high partition sizes, switching to an insertion sort at smaller partion sizes, and switching to heapsort on a partition when worst-case sorting is detected).

You can also currently switch an array to be sorted using mergesort if you require stability in the sorted items, or heapsort if you know ahead of time that quicksort will hit worst case. Plus recently, I've added a shell sort for when you know that your array is already mostly sorted - that'll be in the next release.

TBH, I should have made sure that the code I posted above used the mergesort, so that equal scores would be kept in the correct order.


Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 9th May 2010 00:57
Quote: "SET ARRAY SORT"

Ah, did not see that command

I've known that command was there for a while... but I didn't realize it was that amazingly awesome!


Login to post a reply

Server time is: 2024-11-24 16:00:18
Your offset time is: 2024-11-24 16:00:18