Function: sift Parameters: integer array a[ ]: the \'\'source\'\' array -- it is
ID: 640782 • Letter: F
Question
Function: sift Parameters: integer array a[ ]: the ''source'' array -- it is not modified integer array b[ ]: the ''destination'' array integer n: the length of arrays a[ ] and b[ ] integer p: the index of partition value or ''pivot''; i.e., a[p] is the pivot value. Description: Populates array b[ ] with the elements of all such that: all elements a[p]. In other words, the elements of a[ ] are partitioned into two groups: those a[p] Note: p may or may not be an element of the given array a[ ]. Note: the relative order of elements on either side of the partition can be arbitrary. Return: index of the start of the 2nd partition in the ''destination'' array -- i.e., the index of the first element in the right partition. Note: The 2nd partition may be empty! In this case, n is returned (i.e., one past the last element of the left side). Example: a: (2 18 12 9 1 2 8 11 16 3) n: 10 p: 3 (so the ''pivot'' is a[3]: 9) after sift (one possibility - left-partition highlighted; right partition underlined): b: [2 9 1 2 8 3 18 12 11 16] returns: 6 Note: the ordering produced may be different from the above, BUT the highlighted values MUST come before the underlined values. The return value will still be 6. int sift(int a[ ], int b[ ], int n, int p);Explanation / Answer
int found = -1; for(int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.