Quick Sort Program in C++ Wth Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
int list[5];
int n=5,i;
clrscr();
for(i=0;i<n;i++)
{
printf("Enter the Value for List[%d]:",i);
scanf("%d",&list[i]);
}
void quicksort(int list[],int first,int last);
quicksort(list,0,n-1);
for(i=0;i<n;i++)
{
printf("List[%d]:%d\n",i,list[i]);
}
getch();
}
void quicksort(int list[],int first,int last)
{
int low=first;
int high=last;
int temp;
int pivot=list[(low+high)/2];
while(low<=high)
{
while(list[low]<pivot)
{
low++;
}
while(list[high]>pivot)
{
high--;
}
if(low<=high)
{
temp=list[low];
list[low]=list[high];
list[high]=temp;
low++;
high--;
}
}
if(first<high)
quicksort(list,first,high);
if(low<last)
quicksort(list,low,last);
}
#include<conio.h>
void main()
{
int list[5];
int n=5,i;
clrscr();
for(i=0;i<n;i++)
{
printf("Enter the Value for List[%d]:",i);
scanf("%d",&list[i]);
}
void quicksort(int list[],int first,int last);
quicksort(list,0,n-1);
for(i=0;i<n;i++)
{
printf("List[%d]:%d\n",i,list[i]);
}
getch();
}
void quicksort(int list[],int first,int last)
{
int low=first;
int high=last;
int temp;
int pivot=list[(low+high)/2];
while(low<=high)
{
while(list[low]<pivot)
{
low++;
}
while(list[high]>pivot)
{
high--;
}
if(low<=high)
{
temp=list[low];
list[low]=list[high];
list[high]=temp;
low++;
high--;
}
}
if(first<high)
quicksort(list,first,high);
if(low<last)
quicksort(list,low,last);
}
Quick Sort Program in C++ Wth Source Code
Reviewed by Unknown
on
5:47:00 PM
Rating:
No comments: