0% found this document useful (0 votes)
2 views

quicksort

The document contains a C program that implements the Quick Sort algorithm to sort an array of ten integers. It prompts the user to input ten numbers, displays the unsorted array, sorts it using the Quick Sort function, and then displays the sorted array. The program has a few issues, such as an uninitialized variable 'n' and incorrect loop conditions that may lead to runtime errors.

Uploaded by

Sneha Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

quicksort

The document contains a C program that implements the Quick Sort algorithm to sort an array of ten integers. It prompts the user to input ten numbers, displays the unsorted array, sorts it using the Quick Sort function, and then displays the sorted array. The program has a few issues, such as an uninitialized variable 'n' and incorrect loop conditions that may lead to runtime errors.

Uploaded by

Sneha Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>
void quicksort(int ar[],int first, int last );
int main()
{
int a[10],i,n;
printf("enter any ten number\n");
for(i=0;i<=9;i++)
{
scanf("%d",&a[i]);
}
printf("Element of array \n");
for(i=0;i<=9;i++)
{
printf("%d\t",a[i]);
}
quicksort(a,0,n-1);
printf("Sorted Element of array \n");
for(i=0;i<=9;i++)
{
printf("%d\t",a[i]);
}
return 0;
}

void quicksort(int ar[],int first, int last )


{
int pivot,i,r,j,temp;
if(first<last)
{
pivot=first;
i=first+1;
j=last;
while(i<j)
{
while(ar[i]<=ar[pivot] && i<=last)
i++;

while(ar[j]>ar[pivot]&& j>=first)
j--;
if(i<j)
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}
temp=ar[pivot];
ar[pivot]=ar[j];
ar[j]=temp;
quicksort(ar,first, j-1);
quicksort(ar,j+1,last);
}
}

You might also like