
-----------------------------------
em010
Thu Dec 01, 2011 9:09 pm

Sorting sequences
-----------------------------------
What is it you are trying to achieve?
So I would like to sort a sequence of numbers... the fragment that I made compares numbers and switches them if the previous one is greater than the other.


What is the problem you are having?
 I looped this so that it would compare until it has made a complete loop without swapping any numbers and would like to know what kind of exit statement to use...


Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
The fragment that I will show is this:
*i have already declared variables and have a sequence, just need to sort them

Please specify what version of Turing you are using


-----------------------------------
Tony
Thu Dec 01, 2011 9:46 pm

RE:Sorting sequences
-----------------------------------
[code]
exit when 
[/code]

-----------------------------------
Amarylis
Thu Dec 01, 2011 10:11 pm

Re: Sorting sequences
-----------------------------------
I would use two arrays in here, one for the sorted numbers and one for the unsorted. Use some nested loops in here to make it so you compare all the values of one array to one value of the second array (first array has unsorted values), and to set the value of the second array to the biggest number in the first array's values. It should be simple enough as



%% This is already inside your loops
if array2(x) < array1 (i) then
array2(x) := array1 (i)
end if



then for the next bit, just make sure that the value for array2 (x) is also smaller than array2(x-1)

-----------------------------------
Aange10
Thu Dec 01, 2011 10:46 pm

Re: Sorting sequences
-----------------------------------
Here's a program I got, and re-coded to show you how to bubble sort. Which is what your doing. It works with numbers and with integers.


If you want to use numbers, than so be it. Just make sure that the comparison is instead of Str.Lower() its strint()
(Line 24)
