Hy folks,
I have a "little" contribution to AppGameKit for you.
Shortly after I started to do my first steps in AppGameKit Basic I immediately had to learn that the only kind of collections provided by AppGameKit are arrays.
Now, as I'm pretty used to other languages where stuff like linked lists or hash maps exist I found it kinda frustrating and demotivating to think in arrays and more or less fixed sizes again.
So I decided to create me an include module adding support to linked lists. Actually I also found it a pretty good way to get familiar with AppGameKit Basic.
To cut a long story short: Here it is, my "LinkedList.agc" library, free to use.
Yes it's FREE! However, credits are always very much appreciated
This implementation of linked lists is based on doubly linked lists. So it's possible to jump to next and previous elements.
Features:
* Kinda seamlessly embedding in terms of AppGameKit Basic
* Very comfortable in use
* Supports primitive data-types as well as a key/value concept (KV)
* High performance
* Highly flexible
* Possibility to set/get values in a hard way (performance) as well as in a soft way (flexibility)
* Built-In sorting
* Multi-Level sorting
Note: This is the first version of this lib and so it might still have some bugs - so please keep this in mind. However, if you encounter any bugs please let me know and I will happily fix them. Same is true for any ideas in terms of making this lib better or bigger.
Here's a little example program which quickly shows the use of some of "LinkedList.agc"'s functions:
#Include "LinkedList.agc"
SetVirtualResolution(800, 600)
SetPrintSize(12)
Sync()
list = NewList()
For i = 1 to 20
AddElement(list)
SetElement(list, Random(1, 20))
Next i
PrintInfo(list)
SortList(list, 1)
PrintInfo(list)
SortList(list, 2)
PrintInfo(list)
ClearList(list)
For i = 1 to 40
AddElement(list)
SetElementKV$(list, "a", "a-" + Str(Random(1, 999999)))
SetElementKV(list, "b", RandomSign(Random(0, 999999)))
SetElementKV$(list, "c", "c-" + Str(Random(1, 999999)))
SetElementKV#(list, "d", ValFloat(Str(RandomSign(Random(0, 999))) + "." + Str(Random(0, 999))))
SetElementKV$(list, "e", "e-" + Str(Random(1, 999999)))
Next i
SortListKV(list, "a,b,c,d,e", 1)
PrintInfo$(list)
SortListKV(list, "a,b,c,d,e", 2)
PrintInfo$(list)
End
Function PrintInfo(list)
count = ListSize(list)
Print("List-ID = " + Str(list))
Print("Listsize = " + Str(count))
PrintC("Content > = ")
ResetList(list)
While (NextElement(list) <> 0)
PrintC(str(GetElement(list)) + " ")
EndWhile
Print("")
PrintC("Content < = ")
ResetList(list)
While (PreviousElement(list) <> 0)
PrintC(str(GetElement(list)) + " ")
EndWhile
Print("")
Sync()
Sleep(5000)
EndFunction
Function PrintInfo$(list)
count = ListSize(list)
Print("List-ID = " + Str(list))
Print("Listsize = " + Str(count))
Print("Content = ")
ResetList(list)
While (NextElement(list) <> 0)
Print(GetElementKV$(list, "a") + "|" + GetElementKV$(list, "b"))
EndWhile
Print("")
Sync()
Sleep(5000)
EndFunction
Please find the library behind the according download button.
If you have any questions don't hesitate to ask.
Have phun using my lib!
Cheers,
chrisu.