Write a program to sort elements of array using Quick Sort

Size of array is taken from user.. Elements are entered by user in any order... Sorting is performed..

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<stdio.h> 

  2. #include<conio.h> 

  3. #define max 100 

  4. int a[max],n,i,l,h; 

  5. void main() 


  6. void input(void); 

  7. input(); 

  8. getch(); 


  9.  

  10. void input(void) 


  11. void output(int a[],int n); 

  12. void quick_sort(int a[],int l,int h); 

  13. printf("How many elements in the array : "); 

  14. scanf("%d",&n); 

  15. printf("\n"); 

  16. printf("Enter the elemennts : \n"); 

  17. for(i=0;i<=n-1;i++) 


  18. scanf("%d",&a[i]); 


  19. l=0; 

  20. h=n-1; 

  21. quick_sort(a,l,h); 

  22. printf("Sorted Array :\n "); 

  23. output(a,n); 


  24.  

  25. void quick_sort(int a[],int l, int h) 


  26. int temp,key,low,high; 

  27. low=l; 

  28. high=h; 

  29. key=a[(low+high)/2]; 

  30. do 


  31. while(key>a[low]) 


  32. low++; 


  33. while(key<a[high]) 


  34. high--; 


  35. if(low<=high) 


  36. temp=a[low]; 

  37. a[low++]=a[high]; 

  38. a[high--]=temp; 


  39. //Coding by: Snehil Khanor 

  40. //http://WapCPP.blogspot.com 

  41. } while(low<=high); 

  42. if(l<high) 

  43. quick_sort(a,l,high); 

  44. if(low<h) 

  45. quick_sort(a,low,h); 


  46. void output(int a[],int n) 


  47. for(i=0;i<=n-1;i++) 


  48. printf("%d\n",a[i]); 


  49. }

Check out this stream