NXC: ArraySort algorithm?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: ArraySort algorithm?

Post by HaWe »

hey,
what is the algorithm used by ArraySort?
Bubble Sort?
Insertion Sort?
Merge Sort?
Quick Sort?
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: ArraySort algorithm?

Post by afanofosc »

http://en.wikipedia.org/wiki/Shellsort

Code: Select all

void shell_sort_flt(float* A, UWORD size)
{ 
  UWORD i, j, increment;
  float temp;
  increment = size / 2;
 
  while (increment > 0) { 
    for (i = increment; i < size; i++) { 
      j = i;
      temp = A[i];
      while ((j >= increment) && (A[j-increment] > temp)) { 
        A[j] = A[j - increment];
        j = j - increment;
      }
      A[j] = temp;
    }
 
    if (increment == 2)
       increment = 1;
    else 
       increment = (UWORD)((float)increment / (float)2.2);
  }
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: ArraySort algorithm?

Post by HaWe »

aha,
thank you!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests