Alslamo 3likom
Hello all
i want your help to implement this program in quick sort, i was wrote this program to sort the elements using first element but i want the program to take any random number and do quick sort by making the random element as the first or last in the array .
#include <conio.h>
void qs(int a[],int p, int r);
int part (int a[],int p,int r);
void main(){
int n,i,x,j,k;
int a[100];
clrscr();
printf ("How many number do you want to insert?");
scanf ("%d", &n);
for (i=0; i<n; i++)
scanf ("%d", &a);
qs(a,0,n-1);
printf ("the sorted arry is ");
for (i=0; i<n; i++)
printf ("%d ", a);
getch();
}
void qs (int a[],int p ,int r){
int q;
if (p<r){
q=part(a,p,r);
qs(a,p,q-1);
qs (a,q+1,r);
}
}
int part(int a[],int p,int r){
int x,i,j,k;
x=aبسم الله الرحمن الرحيم;
i=r+1;
for (j=r; j>p; j--){
if (a[j]>=x){
i=i-1;
k=a;
a=a[j];
a[j]=k;}
}
k=a[i-1];
a[i-1]=aبسم الله الرحمن الرحيم;
aبسم الله الرحمن الرحيم=k;
return (i-1);
}
#include <stdio.h>