Trace the following code using the \"array\" space below. public static int What
ID: 3596712 • Letter: T
Question
Trace the following code using the "array" space below.
public static int What(int[]A, int first, int last){
if(first int x = A[first];
int left = first+1; int right = last;
while(left < right){
while(left < right && (A[left] < x)
left++;
while(left < right )&& (A[right] > x)
right--;
if(left < right)
Swap(A[left++],A[right--]);
}
Swap(A[first], A[left-1]);
return left;
}
}
int answer = What(A,0,9);
x=
A:
left=
right=
What did this method do?
8 7 3 11 5 12 1 14 10 9Explanation / Answer
When we trace this array it is giving an apropriate result. it is look like sorting technique. but it is not working currectly.
array modification is - 5 7 3 1 8 12 11 14 10 9
and it is returning 5 means left element.
here
left - 5
right - 9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.