Thread: sorting function?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    46

    sorting function?

    I have been looking through my c book trying to find a built in sorting function but... I can't seem to find one. I know they are their. Can someone tell me of one that I can use to sort a linked list...

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Sort a linked list? Use qsort. You must define and write the compare function that goes into it, tho. Otherwise, write your own. Qsort will also sort strings, numbers, etc, again, provided you supply the compare function...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    46
    What headers do I have to call and what is the qsort usage... qsort(?)

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    stdlib.h

    void qsort( const void* pBase, size_t cntObjects, size_t
    sizeObject, _pfunccmp_t pfuncCmp);

    maybe like :

    int array[5] = {8}, {3}, {7}, {9}, {2};

    qsort(array, 5, sizeof(int), myCompareFunc(??array??) );

    Not sure just how to define that...hmmm...it's a start tho.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It'd actually be like:

    qsort( array, 5, sizeof(int), myCompareFunction );

    When you just use the name of a function, by itself, you are effectivly passing a pointer to the function. So the above should be correct. I say _should_ because I've never had need to actually use qsort.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM