>when the list is in disorder for example (1,3,5,4) still
>says is in ascendent order. How could i fix that?
You wait until after the loop to print the result, obviously:
node *curr = head;
bool ascending = true;
bool descending = true;
while ( curr->next != 0 ) {
if ( curr->data < curr->next->data )
descending = false;
else if ( curr->data > curr->next->data )
ascending = false;
curr = curr->next;
}
if ( ascending )
cout<<"Ascending order\n";
if ( descending )
cout<<"Descending order\n";
if ( !ascending && !descending )
cout<<"No order\n";
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004