Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinms926 authored Feb 11, 2024
1 parent 12ae734 commit fbbfe10
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions quick_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<stdio.h>
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void quicksort(int a[],int s,int e)
{
if(s<e)
{
int p=a[s];
int i=s+1;
int j=e;
while(i<=j)
{
while(i<=e && a[i]<p)
{
i++;
}
while(j>s && a[j]>p)
{
j--;
}
if(i<j)
{
swap(&a[i],&a[j]);
i++;
j--;
}
}
swap(&a[s],&a[j]);
quicksort(a,s,j-1);
quicksort(a,j+1,e);
}
}
void main()
{
int i,n;
printf("Read the array size : ");
scanf("%d",&n);
int a[n];
printf("Enter the elements :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("befor sorting : ");
for(i=0;i<n;i++)
{
printf("%d " ,a[i]);
}
quicksort(a,0,n-1);
printf("After sorting : ");
for(i=0;i<n;i++)
{
printf("%d " ,a[i]);
}
}

0 comments on commit fbbfe10

Please sign in to comment.