Test

int ex01( LinkedList * lst, int x )
{
    assert( *lst != NULL );
    int n = 0;
    NodePtr p = ( *lst )->next;
    NodePtr r = NULL, q = NULL;
    NodePtr pre = NULL;

    if( p == NULL ) return n;

    // reverse small numbers
    //
    ( *lst )->next = NULL;
    q = p;
    while( p != NULL && p->data < x ) {
        r = p->next;
        p->next = ( *lst )->next;
        ( *lst )->next = p;
        p = r;
    }
    q->next = r; pre = q;

    // skip nodes whose values are equal to x
    //
    while( p != NULL && p->data == x ) {
        pre = p;
        p = p->next;
    }

    while( p != NULL ) {
        ++n;
        x = p->data;
        do {
            // remove large even numbers
            //
            if( x % 2 == 0 ) {
                pre->next = p->next;
                delete p;
                p = pre->next;
            }
            // make large odd numbers unique
            //
            else {
                pre = p;
                p = p->next;
            }
        } while( p != NULL && p->data == x );
    }

    return n;
}

你可能感兴趣的:(Test)