1. ## sorting the Linked List

i want to sort the Linked Lists (LL), but it cause a "blurring" in my brain !!
i suppose this situation:
B -> 100
C -> 50
A -> 200
D -> 10

and by sorting it (Descending) we should get
A -> 200
B -> 100
C -> 50
D -> 10

my approach is to get all the numbers in an array and to sort it with array sort, after that i go through the array one by one and then searching the numbers in the LL , i then update the linked list data to equal the array index (i).

better an example
the console output in the last 4 lines is:
2 b
3 c
1 a
4 d

this info say that A have a highest score 200 -> 1.
B have the second score
C the third
D the fourth

not so bad from the practical view point
```uses "LL", "Console"

function TBMain()

Local llRoot, llItem, ptItem  As DWord
local Counter         as long

Dim arr(4) As Long

' -- We create linked list root here, basically a first node

' -- We add item "A" after root node

' -- We add item "B"

' -- We add item "C"

' -- Now we can list data of all nodes
Dim i As Long

For i = 1 To LL_Count(llRoot)
PrintL LL_Data( LL_GetByNumber(llRoot, i) )
Next
PrintL
For i = 1 To LL_Count(llRoot)
llItem = LL_GetByNumber(llRoot, i)
arr(i) = LL_Data(llItem)
Next

Array Sort arr(), Collate Ucase, Descending
For i = 1 To 4
PrintL arr(i)
Next
PrintL
For i = 1 To 4
ptItem = LL_FindByData(llRoot, arr(i))
LL_Update(ptItem, i)
Next

For i = 1 To 4
ptItem = LL_GetByNumber(llRoot, i)
PrintL LL_Data( ptItem ) & " " & LL_Name(ptItem)
Next

' -- Now we free all data
ll_Free(llRoot)

waitkey

end function
```

2. Dear primo,

LL module is a very old module and I think I will remove sooner or later from thinBasic distribution.

Have a look at Core Data Structures: http://www.thinbasic.com/community/s...3356#post93356
In particular AVL Tree that is always internally sorted by the key: http://www.thinbasic.com/public/prod...l?tree_avl.htm
Examples in \thinBasic\SampleScripts\DataStructures\

Ciao
Eros

3. Thanks Eros for the suggestions
in fact i suggest to keep the LL module, because it is one of the computer science subjects, it is fun to use and easy to understand its functions. my above post is not a critic but a toying with the module for the first time. the module contains most needed functions which is easy to use. look as an example http://www.thinbasic.com/community/s...lper&highlight
certainly i will look at the other tools.
regards

4. Yes, sorry. And thanks for you nice example.

My reply is a "critic" to myself grrr
It is a lot of time I wanted to implement a better LL set of functions directly into Core engine but never had time, ... Also wanted to add a native stack and a queue data structure.
I will see what I can do in next releases.

5. Eros, interesting thought. How would effect performance?3

6. Ciao Michael,

what are you referring to regarding performances?

Eros

7. Originally Posted by ErosOlmi
LL module is a very old module and I think I will remove sooner or later from thinBasic distribution.

Please do not remove this. It is extremely useful and nothing is gained by needlessly making things overly complex.

8. LinkedLists, Maps, Stacks are super useful containers and I consider them a must for any good language out there. Same goes for native Json and XML functionality.

9. Originally Posted by Michael Hartlef
LinkedLists, Maps, Stacks are super useful containers and I consider them a must for any good language out there. Same goes for native Json and XML functionality.
LinkedLists and XML, I understand. Stacks I am familiar with from years of studying Compiler/VM design. Maps I do not really understand and I am completely clueless about Json. I do need to try and learn about the last two (especially Json), but since my TBI in 2014, I have a very difficult time trying to learn new things.

Anyway, new to TB and decided to check it out since FBSL has disappeared and I no longer have access to it. Not a lot of choices left for indie programming languages.

10. Hi Kuron
https://web.archive.org/web/20160720...tup/FBSLv3.exe
http://web.archive.org/web/201607201.../FBSLv3bin.zip
:: Full SETUP w. HELP 05th of December 2011 ::
http://www.fbsl.net/setup/FBSLv3.exe [3.4.0.9]
=====================================================
i encourage you to try thinbasic , even i don't know many of the thinbasic features, but i use it every day because it is making the life easier than if we use other languages, it contains many shortcuts. and it contains surprising things, golden eggs etc : look as an example http://www.thinbasic.com/community/s...ghlight=arrays

it is used in some commercial products, such as in control things in a factory of advanced magnetics. in programming there is a commercial product called NeoThinBasic which is calling thinbasic functions to do the job. and much more

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•