Please explain the code below line by line in detail. The code is finished, I just need the explanation .Code in C++: #include #include #include using namespace std; void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition(int arr[],int p,int r) { srand(time(0)); int pivot = rand()%(r-p); pivot += p; swap(arr[r],arr[pivot]); pivot = r; int temp = arr[r]; int i = p-1; for (int j = p; j < r ;j++) { if ( arr[j] < temp ) { i++; swap (arr[i],arr[j]); } } i++; swap (arr[r],arr[i]); return (i); } void quickSort(int arr[], int p, int r) { if (p < r) { int pivot = partition(arr, p, r); quickSort(arr, p, pivot - 1); quickSort(arr, pivot + 1, r); } } int main() { int arr[1000000]; int n; cin>>n; int i; for (i=0; i < n; i++) cin>>arr[i]; quickSort(arr, 0, n-1); for (i=0; i < n; i++) cout<
Please explain the code below line by line in detail. The code is finished, I just need the explanation .Code in C++:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void swap(int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}
int partition(int arr[],int p,int r)
{
srand(time(0));
int pivot = rand()%(r-p);
pivot += p;
swap(arr[r],arr[pivot]);
pivot = r;
int temp = arr[r];
int i = p-1;
for (int j = p; j < r ;j++) {
if ( arr[j] < temp ) {
i++;
swap (arr[i],arr[j]);
}
}
i++;
swap (arr[r],arr[i]);
return (i);
}
void quickSort(int arr[], int p, int r)
{
if (p < r)
{
int pivot = partition(arr, p, r);
quickSort(arr, p, pivot - 1);
quickSort(arr, pivot + 1, r);
}
}
int main()
{
int arr[1000000];
int n;
cin>>n;
int i;
for (i=0; i < n; i++)
cin>>arr[i];
quickSort(arr, 0, n-1);
for (i=0; i < n; i++)
cout<<arr[i]<<";";
return 0;
}
![Quick-Sort
Description
(Lab04-2), your job is to implement the randomized version of Quick-sort. That is, you must
choose a random pivot from the elements in A[p...r] when partitioning the subarray. For more
details, see page 179 of the textbook. The following webpage describes a simple way to obtain a
random integer: http://www.cplusplus.com/reference/cstdlib/rand/
This is the second half of Lab04 and is worth 50 points. In this lab assignment
Input structure
elements (integers) to be sorted, n. Then, the elements follow, one per line.
The input starts with an integer number which indicates the number of
Output structure Output the elements in non-decreasing order. Each element must be fol-
lowed by ;.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5a3a10cd-1c9d-4422-9cda-602d3233f110%2Faa710eb2-bc30-4534-b6c0-a1f14e6e940e%2Fle6lsdk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)