aMethod

This is a discussion on aMethod within the C Programming forums, part of the General Programming Boards category; What does the function below do? Code: int aMethod ( nodePtr list, int (*compar)(void *, void *) ) { int ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    11

    aMethod

    What does the function below do?

    Code:
    int aMethod ( nodePtr list, int (*compar)(void *, void *) ) {
    int b = 1;
    nodePtr o1 = NULL, o2 = NULL;
    for ( ; list ; list = list->next ) {
    o1 = list;
    if ( o2 != NULL && compar(o1->data,o2->data) > 0 ) {
    b = 0;
    break;
    }
    o2 = o1;
    }
    return b;
    }

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    it checks to see if the list is stored in descending order.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > What does the function below do?
    Run it and find out.
    Oh and while you're at it, learn how to post formatted code. Code which is all indented to the left hand side is terribly hard to read.

    > it checks to see if the list is stored in descending order.
    No it doesn't.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    really?

    read the code again.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    I did, you're making way too many assumptions about the nature of the function which compar points to.

    It might be an order, but it could also be an increasing order.

    Or maybe all odd numbers before all even numbers.

    For all anyone knows, the function could be returning rand()

Popular pages Recent additions subscribe to a feed

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