Question: 459 Consider a array which only contains 0, 1, and 2. The 0 elements are placed in the front of the array, the 2 elements

 459 Consider a array which only contains 0, 1, and 2.

459 Consider a array which only contains 0, 1, and 2. The "0" elements are placed in the front of the array, the "2" elements are placed in the tail of the array, and there must exist only ONE"1"element in the array which is placed between "0" and "2" elements. The number of the "0" elements is at least one, and so is the number of the "2" elements. Please finish the program to find out the index of the "1" element and the time complexity of this function must be (logn). (10%) int main 01 int n; // The size of the array has been initialized as n. int array[n]; // The array has been initialized. int ans:// Let answer become the index of the "1" element. 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!