#include<stdio.h>
#include<conio.h>
int a[10];
void q_s(int lb,int ub);
void main()
{
int ub,lb,i,j;
clrscr();
printf("enter elements:");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
q_s(0,9);
printf("elements in the sorted order are:");
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
getch();
}
void q_s(int lb,int ub)
{
int i,j,t;
int flag=1,key;
if(lb<ub)
{
i=lb;
j=ub+1;
key=a[lb];
while(flag)
{
i=i+1;
while(a[i]<key)
{
i=i+1;
}
j=j-1;
while(a[j]>key)
{
j=j-1;
}
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
else
{
flag=0;
}
}
t=a[lb];
a[lb]=a[j];
a[j]=t;
q_s(lb,j-1);
q_s(j+1,ub);
}
}
sample c program codes to learn programming
c code Create temporary file