LAB 2: CS 425 Date: 02/07/2020 Implementation of Quick Sort in C++ Write a program and use random data to sort them using Quick Sort. The pseudocode for Quick Sort is given as below: The above...

1 answer below »
No referencing needed. I will upload the lab and any additional information need in a few hours.


LAB 2: CS 425 Date: 02/07/2020 Implementation of Quick Sort in C++ Write a program and use random data to sort them using Quick Sort. The pseudocode for Quick Sort is given as below: The above algorithm is already illustrated in the class. You may like to use the main that has been developed earlier and used to implement Insertion Sort. ALL: Remember, all the lab assignments have to be completed in the lab, not outside, and be submitted, Must include your code output. LAB 2: CS 425 Date: 02/07/2020 Implementation of Quick Sort in C++ Write a program and use random data to sort them using Quick Sort. The pseudocode for Quick Sort is given as below: The above algorithm is already illustrated in the class. You may like to use the main that has been developed earlier and used to implement Insertion Sort. ALL: Remember, all the lab assignments have to be completed in the lab, not outside, and be submitted, Must include your code output. What you need to do: 1. Declare Header files, using namespace std; 2. Declare two functions void QuickSort(int A[ ], int p, int r); int Partition(int A[], int p, int r); 3. Write the main: Main should declare the array as given below: int * A; int N; cout < “enter="" no="" of="" data:="" “;="" cin="">> N; A = new int [N+1]; // Now get the inputs for A int I; cout < “enter="" “="">< n="">< “number="" of="" data="" “="">< endl;="" for="" (i="1;" i=""><= n;="" i++)="" cin="">> A[I]; //Now call Quicksort QuickSort(A, 1, N); // Display sorted array End main 4. Define two functions by changing pseudocode to C++ functions In order to use the swap function you might need header file cstdlib Also swap is used as swap(A[i], A[j]); Just to show you how the QuiickSort function should be written: void QuickSort(int A[], int p, int r) { int q; if(p < r)="" {="" q="Partition(A," p,="" r);="" quicksort(a,="" p,="" q-1);="" quicksort(a,="" q+1,="" r);="" }="" }="" similarly="" you="" write="" the="" other="" function="" make="" sure="" to="" declare="" any="" variable="" other="" than="" the="" parameters="" inside="" the="" function="" any="" indentation="" means="" you="" need="" to="" put="" those="" statements="" inside="" {="" }="" declare="" i,="" j,="" x="" inside="" the="" partition="" function.="" partition="" function="" int="" partition(int="" a[]="" ,="" int="" p,="" int="" r)="" {="" int="" i,="" j,="" x;="" x="A[r];" i="p-1;" for(j="p;" j=""><= r-1;="" j++)="" {="" if(a[j]=""><= x) { i++; swap(a[i], a[j]); // make sure to include cstdlib header file } } swap(a[i+1], a[r]); return (i + 1); } if this does not work, i need to look at x)="" {="" i++;="" swap(a[i],="" a[j]);="" make="" sure="" to="" include="" cstdlib="" header="" file="" }="" }="" swap(a[i+1],="" a[r]);="" return="" (i="" +="" 1);="" }="" if="" this="" does="" not="" work,="" i="" need="" to="" look="">
Answered Same DayOct 08, 2021

Answer To: LAB 2: CS 425 Date: 02/07/2020 Implementation of Quick Sort in C++ Write a program and use random...

Neha answered on Oct 10 2021
123 Votes
#include
using namespace std;
void swap(int* a, int* b)
{
int t = *a;

*a = *b;
*b = t;
}
int partition (int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j <= high - 1; j++)
{
if (arr[j] < pivot)
{
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here