#include<conio.h>
#include<stdio.h>
#define size 50
void quicksort(int [],int,int);
void main()
{
int arr[size],no,i,j;
printf("\nHow many number you want to enter = ");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("Enter a number = ");
scanf("%d",&arr[i]);
}
quicksort(arr,0,no-1);
printf("\nSorted array is = ");
for(j=0;j<no;j++)
{
printf("%4d",arr[j]);
}
getch();
}
void quicksort(int arr[],int f,int l)
{
int pivot,temp,j,i;
if(f<l)
{
pivot=f;
i=f;
j=l;
while(i<j)
{
while(arr[i]<=arr[pivot]&&i<l)
{
i++;
}
while(arr[j]>arr[pivot])
{
j--;
}
if(i<j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
temp=arr[pivot];
arr[pivot]=arr[j];
arr[j]=temp;
quicksort(arr,f,j-1);
quicksort(arr,j+1,l);
}
}
***********************************************************************************************************************
------------------------------------------------------------------------
output
------------------------------------------------------------------------
How many number you want to enter = 5
Enter a number = 25
Enter a number = 12
Enter a number = 26
Enter a number = 30
Enter a number = 35
Sorted array is = 12 25 26 30 35
***********************************************************************************************************************
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment