Please help me implement this C++ function that is supposed to partition the array a into smaller than pivot and others.
// f is the beginning of the section to be partitioned
// r is the end of the section to be partitioned
// return the first slot of the Large section
int partition(int a[], int f, int r) {
int pivot = a[f];
// pivot is the first element
int small = f;
// small pointer from the left
int large = r;
// large pointer from the right
while (small <= large)
//until they cross
{
// loop for finding out-of-place pairs and swap them
// until the small and large cross
// you will be checking a[small] and a[large] against pivot
// if both are bad (and not crossed yet), swap and then move
// if a[small] is OK, move small
// if a[large] is OK, move large
// TODO: **
}
//end of while
// return the partition point where
// those smaller than pivot are before what is returned
// there is a special cases (small is at the beginning)
// and a regular case
// TODO:
}
to generate a solution
a solution
- The code should be in C and not hard-coded. It should use 2D arrays.arrow_forwardPart 2: Unroll Write a function called unroll, which takes in a square array of arrays (i.e. a grid with n rows and n columns). An input could look like this: const square = [ [1, 2, 3, 4], [5, 6, 7, 8], ]; [9, 10, 11, 12], [13, 14, 15, 16] unroll should take in such a square array and return a single array containing the values in the square. You should obtain the values by traversing the square in a spiral: from the top- left corner, move all the way to the right, then all the way down, then all the way to the left, then all the way up, and repeat. For the above example, unroll should return [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10].arrow_forwardin carrow_forward
- In C programming: Write a main() function using the following requirements:• Define a SIZE constant (the value is irrelevant, but for testing, you may want to keep it small enough – no bigger than 5)• Create an array of course pointers using SIZE• Dynamically allocate each element of the array• Call inputAllCourses()• Call printAllCourses().arrow_forwardC++arrow_forwardC++ In this lab, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. Parallel Arrays First, you have to define several arrays in your main program: employee names for each employee hourly pay rate for each employee total hours worked for each employee gross pay for each employee You can use a global SIZE of 50 to initialize these arrays. Second, you will need a two dimension (2-D) array to record the hours worked each day for an employee. The number of rows for the 2-D array should be the same as the arrays above since each row corresponds to an employee. The number of columns represents days of the week (7 last I looked). Functions Needed In this lab, you must read in the employee names first because this…arrow_forward
- In C++ Create an array of head pointers, statically allocated of size 101 of that type: Now, create a pointer that can point to the first element: Show how to dynamically allocate an array of 101 elements of head pointers: Write the code to initialize each element to NULL: Rewrite the code to initialize each element to NULL using pointer arithmetic:arrow_forwardIn C++, Can you please look at the code below and revise/fix so it will work according to instructions and criteria. Instruction 1) Write a function that copies a 1D array to a 2D array. The function’s prototype is bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant size = NCOLS * nrows the function returns true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and 2d array indices is 2d row index = 1d array index / NCOLS 2d column index = 1d array index modulus operator NCOLS 2) Write a function that copies a 2D array to a 1D array. The function’s prototype is bool copy2DTo1D(int d2[][NCOLS, int nrows, int d1[], int size); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant the function return true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and…arrow_forwardC++ pleasearrow_forward
- You are designing a function that will manipulate an array of integers. It needs to work for arrays of any length. What is the minimum number of parameters your function will have?arrow_forwardwrite in html and scriptarrow_forwardIn C++ please ! Write a Program that: Initializes an interger array size of 10 with random intergers in range [10,30]. Use a function named 'initialized_array' to acheive that. Determine if all array elements are distinct from each other or not.Use boolean function named 'distinct_elements' to achieve that function 'distinct elements, if the elements in the array are duplicate print out, elements are duplicate if not print out arrayarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education