#include<stdio.h>
#include<conio.h>
#define max 10
int a[max], n, i, l, h;
void main()
 {
 void input(void);
 input();
 getch();
 }

void input(void)
 {
 void quick_sort(int a[], int l , int h);
 void output(int a[], int n);
 clrscr();
 printf("\n\nHow MAny Element to You Stored (Array Size) : ");
 scanf("%d",&n);
 printf("\n");
 
 for(i=0;i<=n-1;i++)
 {
 printf("Enter element : \n");
 scanf("%d",&a[i]);
 }
 l = 0;
 h = n - 1;
 quick_sort(a, l, h);
 printf("\n\nAfter Sorted Array :\n");
 output(a, n);
 }

void quick_sort(int a[], int l, int h)
 {
 int temp , key, low, high;
 low = l;
 high = h;
 key = a[(low + high)/2];
 do
 {
 while(key > a[low])
 {
 low++;
 }
 while(key < a[high])
 {
 high--;
 }
 if(low <= high)
 {
 temp = a[low];
 a[low++] = a[high];
 a[high--] = temp;
 }
 }
 while(low <= high);
 if(l < high)
 quick_sort(a, l, high);
 if(low < h)
 quick_sort(a, low, h);
 }

void output(int a[],int n)
 {
 for(i=0;i<=n-1;i++)
 {
 printf("%d\n",a[i]);
 }
 }
OUTPUT
How Many Element to You Stored (Array Size) : 5

Enter element : 40 
Enter element : 10 
Enter element : 30 
Enter element : 60 
Enter element : 20 

After Sorted Array :
 10
 20
 30
 40
 60

Leave a Reply

Subscribe to Posts | Subscribe to Comments

All Notes on BCA

All Notes  on BCA
BCA all subjects notes

Total Pageviews

Translate

Powered by Blogger.

Copyright © All Notes on BCA