sorting function?

This is a discussion on sorting function? within the C Programming forums, part of the General Programming Boards category; I have been looking through my c book trying to find a built in sorting function but... I can't seem ...

  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,655
    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...

  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,655
    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.

  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, 06: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, 09:18 AM
  5. Replies: 4
    Last Post: 11-23-2003, 06:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21