Thread: JavaScript like sort algorithm?

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Question JavaScript like sort algorithm?

    Does anybody know JavaScript's sort function?

    Any implementation in C?

    I like the compare function to sort complex thing, its easy to do and undestand and they said JavaScript's sort is the fastest sorting algorithm ever, is that right?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I like the compare function to sort complex thing, its easy to do and undestand
    C's qsort function also takes a compare function, except that being a lower level language, it isn't as easy to do and understand.

    they said JavaScript's sort is the fastest sorting algorithm ever, is that right?
    I don't know JavaScript, but I would suspect sort is a method, not an algorithm. I would expect it to use internally some sorting algorithm. (That is, I don't see a reason why the sort routine in other languages couldn't be implemented using the same algorithm.)

    C's qsort function, as the name implies, should be an implementation of the quicksort algorithm. C++'s sort function may be implemented using any sorting algorithm that meets the complexity/behaviour requirements (but there is no reason to assume STL implementors wouldn't choose the best algorithms available).

    But you can be sure that a general-purpose sorting algorithm cannot be faster than a special-purpose algorithm for specific situations. For example, you can sort integers (in a limited range?) with linear complexity O(n), whereas a general sorting algorithm can never be better than O(n * log n).
    Last edited by anon; 07-27-2008 at 04:01 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Yeah, you right anon...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with debug (bubble sort algorithm)
    By lbraglia in forum C Programming
    Replies: 5
    Last Post: 10-19-2007, 05:24 PM
  2. choosing right sort algorithm
    By Micko in forum C++ Programming
    Replies: 15
    Last Post: 05-29-2006, 10:38 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Replies: 2
    Last Post: 05-06-2003, 08:34 AM
  5. Sort algorithm and an ugly error
    By Trauts in forum C++ Programming
    Replies: 7
    Last Post: 02-25-2003, 12:36 PM