Provide an explanation per line on this quick sort algorithm program. Program: #include #include using namespace std; void aaswap(int* aap, int* aaq) { int aatemporary = *aaq; *aaq = *aap; *aap = aatemporary; } int aapartition (int aaarray[], int aalower, int aaupper) { int aai = (aalower - 1); for (int aaj = aalower; aaj < aaupper; aaj++) { if (aaarray[aaj] >aaarray[aaupper]) { aai++; aaswap(&aaarray[aai],&aaarray[aaj]); } } aaswap(&aaarray[aai + 1], &aaarray[aaupper]); return (aai + 1); } void aaquickSort(int aaarray[], int aalower, int aaupper) { if (aalower < aaupper) { int aapivotIndex = aapartition(aaarray, aalower, aaupper); aaquickSort(aaarray, aalower, aapivotIndex - 1); aaquickSort(aaarray, aapivotIndex + 1, aaupper); } } int main() { int *a,n,i; cout<<"Enter number of integers: "; cin>>n; a=(int*)malloc(n*sizeof(int)); for(i=0;i>a[i]; } aaquickSort(a,0,n-1); cout<<"\nSorted Integers: "; for(i=0;i
Provide an explanation per line on this quick sort
Program:
#include<iostream>
#include<stdlib.h>
using namespace std;
void aaswap(int* aap, int* aaq)
{
int aatemporary = *aaq;
*aaq = *aap;
*aap = aatemporary;
}
int aapartition (int aaarray[], int aalower, int aaupper)
{
int aai = (aalower - 1);
for (int aaj = aalower; aaj < aaupper; aaj++)
{
if (aaarray[aaj] >aaarray[aaupper])
{
aai++;
aaswap(&aaarray[aai],&aaarray[aaj]);
}
}
aaswap(&aaarray[aai + 1], &aaarray[aaupper]);
return (aai + 1);
}
void aaquickSort(int aaarray[], int aalower, int aaupper)
{
if (aalower < aaupper)
{
int aapivotIndex = aapartition(aaarray, aalower, aaupper);
aaquickSort(aaarray, aalower, aapivotIndex - 1);
aaquickSort(aaarray, aapivotIndex + 1, aaupper);
}
}
int main()
{
int *a,n,i;
cout<<"Enter number of integers: ";
cin>>n;
a=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
cout<<" Enter Integer No. "<<i+1<<": ";
cin>>a[i];
}
aaquickSort(a,0,n-1);
cout<<"\nSorted Integers: ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
}

Step by step
Solved in 3 steps

Insert the explanation line by line separate each explanation.








