We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge 9 - Quick sort
#21
(10-28-2024, 09:22 PM)jrmrhrb00 Wrote: AB,

This is what creates the LDArray

'creates ldArray from indices
status=LDArray.CreateFromIndices(name)
TextWindow.WriteLine(status)

Status even shows you Array1.

JR

JR,

I don't know how much your code has changed compared to your code that I have.

But, in the version of your code that I now see on my computer, line "status=LDArray.CreateFromIndices(name)" is located AFTER line "LDArray.SetValue(status, i, Math.GetRandomNumber(10))".

That is, you FIRST try to use an array that has not yet been created, and only THEN write "CreateFromIndices".

Give us the latest version of your code.

( Unfortunately, I have to go to bed. See you later. Wink )

AB
Reply
#22
I assume that the LDArrays cannot be output with Textwindow.WriteLine(). Only the internal name of the array appears. The sort function is OK.

Code:
name = LDArray.Create(10)
For i = 1 To 10
  value = Math.GetRandomNumber(10)
  result = LDArray.SetValue( name, i , value)
TextWindow.WriteLine("Name [ " + i + " ]  :" + value)
EndFor
result=LDArray.Sort(name)
TextWindow.WriteLine("Result Sort: " + result)
For i = 1 To 10
  value = LDArray.GetValue( name, i )
  TextWindow.WriteLine("Name [ " + i + " ]  :" + value)
EndFor

That would be the simplest way of sorting.
But I think that the numbered challenges should be solved without extensions.
This is probably more about the Quicksort algorithm and a possible comparison with an AI solution.

Have fun
Scout
Reply
#23
Scout,

This failed too. Variable Name is used, but value is not assigned. First error.

Name [ 1 ]  :7
Name [ 2 ]  :6
Name [ 3 ]  :6
Name [ 4 ]  :9
Name [ 5 ]  :7
Name [ 6 ]  :1
Name [ 7 ]  :3
Name [ 8 ]  :9
Name [ 9 ]  :6
Name [ 10 ]  :9
Result Sort: FAILED
Name [ 1 ]  :FAILED
Name [ 2 ]  :FAILED
Name [ 3 ]  :FAILED
Name [ 4 ]  :FAILED
Name [ 5 ]  :FAILED
Name [ 6 ]  :FAILED
Name [ 7 ]  :FAILED
Name [ 8 ]  :FAILED
Name [ 9 ]  :FAILED
Name [ 10 ]  :FAILED
Press any key to continue... 

The rest of them. Notice that the sort did fail.
Reply
#24
(translated by Google translator)

Hi all.  Shy

Most likely, only LitDev will be able to fix this problem.

However, we can continue to complete the task without using the extension.

First of all, I try to develop my own quick sort method.  Rolleyes
I deliberately do not study methods that already exist. I'm interested in inventing things that I don't know yet.

I wish everyone good luck.
Reply
#25
Hii JR
On desktop i fixed your code no error in extension.
JXNC572.000-0

a more simpler version: MVHG984.000

ChatGPT's Solution Without third party library :
LBBP129.000
ZS
[-] The following 1 user Likes z-s's post:
  • Scout
Reply
#26
Z-S,

Great job. I was sure I was doing something wrong but couldn't figure out what. Basically, I wasn't getting or setting the values for a LDArray. The amazing thing is there is no guidance any where on how to use those arrays. Used to be in the old small basic forum, but that is gone. Maybe, this is something that LitDev would write an article on.

Thanks,

JR
Reply
#27
(10-28-2024, 10:31 PM)jrmrhrb00 Wrote: Scout,

This failed too. Variable Name is used, but value is not assigned. First error.

Name [ 1 ]  :7
Name [ 2 ]  :6
...
Name [ 10 ]  :9
Result Sort: FAILED
Name [ 1 ]  :FAILED
Name [ 2 ]  :FAILED
...
Name [ 10 ]  :FAILED
Press any key to continue... 

The rest of them. Notice that the sort did fail.

Hi all.  Shy
It's strange, but Scout's code works for me without errors. Huh

I don't understand anything...
Reply
#28
Well done all,

LBBP129.000 is bubblesort not quicksort (bubblesort very slow for large lists compared to quicksort), also only 5 not random elements

LDArray is good for multi-dimensional arrays, where the max number of elements in each dimension is fixed initially
LDList is good for 1D arrays, where the number of elements can grow dynamically
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#29
Got it
https://en.m.wikipedia.org/wiki/Quicksort
ZS
Reply
#30
Found this nice demo on sorting algorithms and extended it to 1024 random numbers for Challenge 9.
It doesn't use extensions and is therefore a bit slow. But it could also be due to the shape moves.
Program ID: JCXS148.000

Once we have created the algorithm for quicksort in Small Basic, we could extend this demo with quicksort.  Smile

   
[-] The following 1 user Likes Scout's post:
  • AbsoluteBeginner
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)