代码中的关键变化可能是这样的:
// while loop from 0 to n - 2; i initially = 0
if( arr[i + 1] != element && arr[i] != element) i += 2;
else if(arr[i] == element){ cout << "Element present at: " << i; }
else{ cout << "Element is present at: " << i + 1; return 0; }
你怎么看?