0% found this document useful (0 votes)
7 views2 pages

5.quick Sort

The document presents a C++ implementation of the Quick Sort algorithm. It includes functions for swapping elements, partitioning the array, and recursively sorting the array. The main function prompts the user to input an array of integers and then displays the sorted array.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

5.quick Sort

The document presents a C++ implementation of the Quick Sort algorithm. It includes functions for swapping elements, partitioning the array, and recursively sorting the array. The main function prompts the user to input an array of integers and then displays the sorted array.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

5.

Quick sort

#include<iostream.h>

#include<conio.h>

void swap(int*a, int*b)

int t=*a;

*a=*b;

*b=t;

int partition(int a[20], int lo,int hi)

int pivot=a[hi];

int i=lo-1;

for(int j=lo;j<=hi-1;j++)

if(a[j]<=pivot)

i++;

swap(&a[i],&a[j]);

swap(&a[i+1],&a[hi]);

return i+1;

void sort(int a[20],int lo,int hi)

if (lo<hi)
{

int p=partition(a,lo,hi);

sort(a,lo,p-1);

sort(a,p+1,hi);

void main()

clrscr();

int a[20];

int n;

int i;

cout<<"\n Enter a number of Element in array:";

cin>>n;

cout<<"\n Enter a element seperated by space:\n";

for(i=0;i<n;i++)

cin>>a[i];

sort(a,0,n-1);

cout<<"\n Sorted list is: \n ";

for(i=0;i<n;i++)

cout<<a[i]<<"\t";

getch();

You might also like