Quick Sort
#include<iostream>
#include<conio.h>
using namespace std;
void quickSort(int arr[], int left, int right)
{
int l = left, r = right;
int a;
int pivot = arr[((left + right) / 2)];
while (l <= r)
{
while (arr[l] < pivot)
l++;
while (arr[r] > pivot)
r--;
if (l<=r)
{
a = arr[l];
arr[l] = arr[r];
arr[r] = a;
l++;
r--;
}
}
if (left<r)
quickSort(arr, left, r);
if (l< right)
quickSort(arr, l, right);
}
int main()
{
int arr[10];
cout<<"Enter oderable data: ";
for(int i=0;i<10;i++)
cin>>arr[i];
for(int i=0;i<10;i++)
quickSort(arr,0,9);
cout<<"Data after Quick Sorting: \n\t| ";
for(int i=0;i<10;i++)
cout<<arr[i]<<" | " ;
getch();
return 0;
}
#include<conio.h>
using namespace std;
void quickSort(int arr[], int left, int right)
{
int l = left, r = right;
int a;
int pivot = arr[((left + right) / 2)];
while (l <= r)
{
while (arr[l] < pivot)
l++;
while (arr[r] > pivot)
r--;
if (l<=r)
{
a = arr[l];
arr[l] = arr[r];
arr[r] = a;
l++;
r--;
}
}
if (left<r)
quickSort(arr, left, r);
if (l< right)
quickSort(arr, l, right);
}
int main()
{
int arr[10];
cout<<"Enter oderable data: ";
for(int i=0;i<10;i++)
cin>>arr[i];
for(int i=0;i<10;i++)
quickSort(arr,0,9);
cout<<"Data after Quick Sorting: \n\t| ";
for(int i=0;i<10;i++)
cout<<arr[i]<<" | " ;
getch();
return 0;
}