Page 1 of 1

show low value first

Posted: Mon Jan 06, 2014 9:20 am
by siliconchip
hi if i have say a variable byte called number[2] and have 3 values within for example
number[0] = 71
number[1] = 4
number [2] = 52
how would I arrange the program to show the lowest value first ?

Re: show low value first

Posted: Mon Jan 06, 2014 10:48 am
by Benj
Hello,

You would have to loop through the array each time and either populate another array with the correct order from low to high or re-parsing through the entire array to pull out each new value by recording the current value and comparing with the current position in the array.

Re: show low value first

Posted: Mon Jan 06, 2014 4:33 pm
by siliconchip
hi benj thanks for the reply but im still a little fazed by this :oops:

Re: show low value first

Posted: Mon Jan 06, 2014 4:45 pm
by Benj
Hello,

I can do you a simple example.

Which method is more acceptable for you, reordering the array into another array of the same size once (RAM based) or reparsing through the entire array on each iteration (ROM based)?

Re: show low value first

Posted: Mon Jan 06, 2014 5:08 pm
by LeighM
You could also try a Bubble Sort. Google and wiki for an algorithm :D

Re: show low value first

Posted: Mon Jan 06, 2014 5:32 pm
by medelec35
LeighM wrote:You could also try a Bubble Sort
I did a bubble sort some time ago:
http://www.matrixmultimedia.com/mmforum ... 73&#p22074
You many need to look at the whole of the thread to see which flowchart would suit you the most (if any?).

Martin

Re: show low value first

Posted: Mon Jan 06, 2014 5:59 pm
by siliconchip
hi benj im not sure about ram or rom based , martin I looked at the bubble sort but im after a set of 3 random numbers being picked and being then placed in variables ie number[0],number[1]and number[2] these are displayed again in order ie if 40 71 5 were picked then they would be shown as 5, 40, 71,

Re: show low value first

Posted: Mon Jan 06, 2014 8:08 pm
by siliconchip
hi martin / benj I have added a flow chart that picks my 3 numbers then displays them but im looking at them being placed from low to high

Re: show low value first

Posted: Mon Jan 06, 2014 9:06 pm
by medelec35
Hi Bob,
I implemented the bubble sort that I posted a link to.
Hopefully it's working the way you want it to.

Hint If you never want a repeated random number, e.g 4,6, & 4 then check out my Lottery generator:
http://www.matrixmultimedia.com/mmforum ... =26&t=8025

Martin

Re: show low value first

Posted: Mon Jan 06, 2014 9:23 pm
by siliconchip
hi martin this is perfect exactly what i have been trying to achieve but I was way off the mark it works perfect, once again many thanks for helping me out and thanks to benj i now intend to interrogate the bubble sort flowchart and try to break it down to work out how it operates once again thanks :P

Re: show low value first

Posted: Tue Jan 07, 2014 10:04 am
by medelec35
Hi Bob,
Your welcome.
Just glad it's what you're after.

Thanks for letting us know. :)

Martin

Re: show low value first

Posted: Tue Jan 07, 2014 1:54 pm
by siliconchip
martin I have attempted to make a better random generator, and im happy with it but I tried to add the bubble sort part as per version 2 but I cannot get it to work as my new flowchart is different ive spent most of the day trying to add it in various places changing variables etc but no joy. HELP :?

Re: show low value first

Posted: Tue Jan 07, 2014 2:22 pm
by medelec35
Hi Bob,
On V2a I added a bubble sort macro
That macro was missed out in version 3.

Martin

Re: show low value first

Posted: Tue Jan 07, 2014 2:36 pm
by siliconchip
hi martin I had added the bubblesort macro when I was trying to get it to work I used V2 as a guide to see where you had added the macro in the main flow chart but being up late working on a new generator as well as today left me getting in knots so i removed the macro leaving a clean sheet ready for some help, but once again you have sorted me out again many many thanks, :D

Re: show low value first

Posted: Tue Jan 07, 2014 7:16 pm
by medelec35
Ah I see, fair enough.
If you need help in finding out how the routine works, then by all means give me a shout.

Martin

Re: show low value first

Posted: Tue Jan 07, 2014 8:00 pm
by siliconchip
hi martin im going to go through the code to try and work it out but I shall take you up on your offer if i get stuck cheers