c++ - integer comparison incorrect or not comparing -
i have array such:
int array[] = { 1,3,2,5,4,7,6,9,8,10 }; when try step through array , compare numbers none of them trigger if condition thereby triggering swap:
for( int i=0; i<9; i++) { if (array[i] > array[i++]) { cout << "swapping" << array[i] << " " << array[i++]<< endl; int temp = 0; temp = array[i]; array[i] = array[i++]; array[i++] = temp; temp = 0; } }
is there detail of comparing integers missing? treated differently because in array?
i++ means "return i , set i = + 1". each time you're using i++ increasing i 1 ruins loop. use i+1 instead.
Comments
Post a Comment