quick sort programs with output

#include<conio.h>
#include<stdio.h>
#define size 50
void quicksort(int [],int,int);

void main()
{
 int arr[size],no,i,j;
 printf("\nHow many number you want to enter = ");
 scanf("%d",&no);

 for(i=0;i<no;i++)
 {
  printf("Enter a number = ");
  scanf("%d",&arr[i]);
 }
 quicksort(arr,0,no-1);

 printf("\nSorted array is = ");
 for(j=0;j<no;j++)
 {
  printf("%4d",arr[j]);
 }

 getch();
}
void quicksort(int arr[],int f,int l)
{
 int pivot,temp,j,i;

 if(f<l)
 {
         pivot=f;
         i=f;
         j=l;

         while(i<j)
   {
             while(arr[i]<=arr[pivot]&&i<l)
      {
                             i++;
      }
             while(arr[j]>arr[pivot])
      {              
               j--;
      }
             if(i<j) 
    {
                 temp=arr[i];
                  arr[i]=arr[j];
                  arr[j]=temp;
             }
         }

         temp=arr[pivot];
         arr[pivot]=arr[j];
         arr[j]=temp;
         quicksort(arr,f,j-1);
         quicksort(arr,j+1,l);

    }

}

***********************************************************************************************************************
------------------------------------------------------------------------

        output

------------------------------------------------------------------------


How many number you want to enter = 5
Enter a number = 25
Enter a number = 12
Enter a number = 26
Enter a number = 30
Enter a number = 35

Sorted array is =   12  25  26  30  35

***********************************************************************************************************************
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment