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
llRoot = LL_Add(0, "B", 100)

' -- We add item "A" after root node
llItem = LL_Add(llRoot, "C", 50)

' -- 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. @Primo -- Thank you VERY much for those working links. I did try archive.org first, but it is so difficult to find a capture that actually has working links. You encounter enough links that do not work, and you give up. Now, if I can find a working link to the FBSL v3.5 RC2.zip file, I will be back in shape and where I need to be.

thinBasic is impressive. I do find the forums difficult to navigate (way too many sections which makes it cluttered IMHO), but I am impressed with TB, and this is from somebody who is not a huge fan of interpreted languages. I have been trying all of the examples. Feature-wise, thinBasic is what PB should have been. I am struggling with TB a good bit, but that is 100% on me not knowing/understanding what I am doing.

#### Posting Permissions

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