Thanks a lot Rene. I appreciate!
And what about:
Printl instead of Console_WriteLine
Print instead of Console_Write
Waitkey instead of Console_WaitKey
just do some math:
How about Strings?Uses "Console" Double a = 1.234 Double b = 5.678 console_writeLine("A = " + str$(a) ) console_writeLine("B = " + str$(b) ) a += b b = a - b a = a - b console_writeLine("A = " + str$(a) ) console_writeLine("B = " + str$(b) ) console_waitKey()
or in thinBasic:Uses "Console" String A = "World !" String B = "Hello " Console_WriteLine(A + B) A += B B = Left$( A, Len(A) - Len(B) ) A = Right$(A, Len(A) - Len(B) ) console_writeLine(A + B) console_waitKey()
'... Swap A,B '...
Last edited by ReneMiner; 06-03-2013 at 20:16.
I think there are missing some Forum-sections as beta-testing and support
Thanks a lot Rene. I appreciate!
And what about:
Printl instead of Console_WriteLine
Print instead of Console_Write
Waitkey instead of Console_WaitKey
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
We can also swap two Numbers using Bitwise operator
var arg1 = int.Parse(Console.ReadLine());
var arg2 = int.Parse(Console.ReadLine());
Console.WriteLine("\n Before swapping arg1= {0} and arg2 = {1}", arg1, arg2);
arg1 = arg1 ^ arg2;
arg2 = arg1 ^ arg2;
arg1 = arg1 ^ arg2;
Here is full sample code
https://corevoila.in/coding-problems...wise-operator/
Last edited by cbz6109; 21-07-2020 at 16:46.
Thank you for sharing the trick,
it looks like this with thinBasic syntax:
uses "console" print "Please enter the arg1: " int32 arg1 = console_readline() print "Please enter the arg2: " int32 arg2 = console_readline() Printl(strformat$("Before swapping arg1= {1} and arg2= {2}", arg1, arg2)) arg1 = arg1 xor arg2 arg2 = arg1 xor arg2 arg1 = arg1 xor arg2 Printl(strformat$("After swapping arg1= {1} and arg2= {2}", arg1, arg2)) WaitKey
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Hello,
Little question
Which method is less or more time consuming.
The time may be an important parameter, example bubble sorting.
Regards
Therefore i would suggest If your Bubbles are Stores to a String-Array to use Array Sort.
If you stored values in a different manner - f.e. stored at heap-memory or AS subelements of udt it's probably still faster to sort the even numeric Elements as strings using the workaround and take advantage of a special behaviour of the array-functions - Here Array Extract - which will Sort the source-Array before extracting any values since the thinBasic-array-handling functions are incredible fast.
So depending in how you stored Bubbles i would either convert them into an array or make the pointers to the bubbles an array to make use of array-functions -
When your program uses "Dictionary" to store the data that is- in any case- the fastest and Most straightforward solution: it offers to sort however you like and it does not require to transfer any data before sorting. If you need to sort often in your program its worth to consider the use of Dictionary-module.
If you are using "UI"-module anyway, create a listbox (if your Bubbles are values in an array of simple datataype, Listview If you have Data in an udt-array). Set its sorted-property true and Set to ascend or descend, fill in numeric values ("nVal") with leading zeros- or If in range of 32bit integer (Long, DWord) simply using Hex$(nVal, 8 ) :
8 makes it formatted to 8 digits and all displayable values while f.e. MKE$(nVal), -range of Extended number-will result in a String containing Digits that can not be displayed if not re-converted (use CV...-functions). The list can stay invisible (mainly its enabled).
It might not be the fastest way to sort - but very simple and it's easy to keep overview - you know anytime where your values are and what they are doing.
And for the thinbasic-core-array-functions as said - If it's obviously not offered by Array Sort - use Array Extract with an easy extraction-pattern or even to select a few Special Elements and "abuse" the behaviour of Array Extract that will Sort the source-Array.
Array Extract even offers to Extract pointed Elements - so you could make use of its behaviour to sort the source-Array and collect the VarPtr()s to your bubbles in an ordinary Array of DWord-values
Last edited by ReneMiner; 30-07-2020 at 10:55.
I think there are missing some Forum-sections as beta-testing and support
Bookmarks