Number Sort Algorithm


Closed Thread
Results 1 to 40 of 55

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I've found a few nifty tricks like this on the Microchip forum in the Tips &
    Tricks section http://forum.microchip.com/tm.aspx?m=165770

    Really gets one to thinking.

    The PIClist is another good resource, but the signal-to-noise ratio there can
    be pretty high.

    Nice job on the Flash XOR gate Darrel...;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Thank you, thank you,

    So now that I've proven to myself that it works, ...
    back to the topic ...

    I think that changes Melanie's Sort from Post #4, to ...
    Code:
    	CounterA var Byte
    	RawData var Byte [16]
    	.. ..
    
    		'
    		'	Sort Array
    		'	----------
    SortArray:
    	CounterA=0
    SortLoop:
    	If RawData(CounterA+1) < RawData(CounterA) then
    		RawData(CounterA)     = RawData(CounterA) ^ RawData(CounterA+1)
    		RawData(CounterA+1+0) = RawData(CounterA) ^ RawData(CounterA+1)
    		RawData(CounterA)     = RawData(CounterA) ^ RawData(CounterA+1)
    		If CounterA > 0 then CounterA=CounterA-2
    		endif
    	CounterA=CounterA+1
    	If CounterA < 15 then goto SortLoop
    	Return
    Now I've got to wonder if it makes any difference?

    edit: The added array operations would probably even slow it down.
    <br>
    Last edited by Darrel Taylor; - 26th July 2007 at 13:07. Reason: .
    DT

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,146


    Did you find this post helpful? Yes | No

    Default

    The one thing for sure is that code will use one variable less.

    As for speed, I don't know. Operation either on swap or with the XOR thing i believe are the same...

    Ioannis

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    You know, if you say Super-cala-fragile-listic-expealidoius, backwards, at exactly 3:03 am, the Blair Witch will appear before you and grant you with exactly one wish. Be careful what you wish for though.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,146


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    You know, if you say Super-cala-fragile-listic-expealidoius, backwards, at exactly 3:03 am, the Blair Witch will appear before you and grant you with exactly one wish. Be careful what you wish for though.
    Didn't that was said by Mary Poppins? Iliked it a lot!

    But how does this connect with the above? Sorry I cannot understand, as english is second language to me.

    Ioannis

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It doesn't work (because Trent forgot to use his spellchecker)... I'm worried about the 'fragile' section in the middle of the word...

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,146


    Did you find this post helpful? Yes | No

    Default

    and needs an 'c' in expealidoius like: expealidocius

    Ioannis

  8. #8
    Join Date
    Mar 2005
    Location
    Cocoa, Florida
    Posts
    44


    Did you find this post helpful? Yes | No

    Default Re: Number Sort Algorithm

    Quote Originally Posted by Darrel Taylor View Post
    Thank you, thank you,

    So now that I've proven to myself that it works, ...
    back to the topic ...

    I think that changes Melanie's Sort from Post #4, to ...
    Code:
    	CounterA var Byte
    	RawData var Byte [16]
    	.. ..
    
    		'
    		'	Sort Array
    		'	----------
    SortArray:
    	CounterA=0
    SortLoop:
    	If RawData(CounterA+1) < RawData(CounterA) then
    		RawData(CounterA)     = RawData(CounterA) ^ RawData(CounterA+1)
    		RawData(CounterA+1+0) = RawData(CounterA) ^ RawData(CounterA+1)
    		RawData(CounterA)     = RawData(CounterA) ^ RawData(CounterA+1)
    		If CounterA > 0 then CounterA=CounterA-2
    		endif
    	CounterA=CounterA+1
    	If CounterA < 15 then goto SortLoop
    	Return
    Now I've got to wonder if it makes any difference?

    edit: The added array operations would probably even slow it down.
    <br>
    This sort just saved my butt, thank you.
    As the PICs get faster, speed is less of a consideration.

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 17:50
  3. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  4. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55
  5. Split number into variables
    By psmeets in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th January 2004, 04:15

Members who have read this thread : 3

You do not have permission to view the list of names.

Posting Permissions

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