beingtopper.jkp@gmail.com
+91-8700702530
Free Demo

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us

Being Topper

  • About Us
  • Knowledge Base
  • Modules
  • Branches
    • Ajmer
    • Tilak Nagar
    • Noida
    • Chandigarh
    • Mumbai
  • Contact Us
Algorithm Design and analysis ProgramsB.tech notesC++ programInformation technology

C++ PROGRAM ON QUICK SORT

Being Topper 24/05/2013 0 Comments

QUICK SORT

QuickSort algorithm works on  a Divide and Conquer technique. It select an element as pivot and splits the given array around the picked pivot. There are lots of different versions of quickSort that select pivot in different ways.

  1. Always pick first element as pivot.
  2. Always pick last element as pivot
  3. Pick a random element as pivot.
  4. Pick median as pivot.

The main process in quickSort is partition(). Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. All this should be done in linear time.

 

check this video of Quick-sort with Hungarian folk dance


WRITE A PROGRAM ON QUICK -SORT
#include<iostream.h>

#include<conio.h>

#include<stdio.h>

int  partition(int arr[], int p,int r);

void  quicksort(int arr[],int p,int r)

{ int q;

if (p<r)

{  q= partition(arr,p,r);

quicksort(arr,p,q-1);

quicksort(arr,q+1,r);

}

int  partition(int  arr[],int  p, int r)

{    int t, k,y,i,x;

x=arr[r];

i=p-1;

for(j=p;j<r;j++)

{  if(arr[j]<=x)

{  i=i+1;

t=arr[i];

arr[i]=arr[j];

arr[j]= t;

}

}

k=arr[i+1];

arr[i+1]=arr[r];

arr[r]=k;

y = i+1;

return y  ; }

void main()

{

int arr[8],i;

cout<<“Enter array elements : \n”;

for(i=0;i<8 ;i++)

{  cin>>arr[i]; }

cout<<“\n The array elements are : \n”;

for(i=0;i<8;i++)

{   cout<<arr[i];  }

quicksort(arr,1,8);

cout<<” sorted array elements are :\n”;

for(i=0;i<8;i++)

cout<<  arr[i];

getch();

}
OUTPUT :

output

Algorithm and design analysis C++ PROGRAM ON QUICK SORT C++ PROGRAM ON QUICK SORT IMPLEMENTATION quick sort
AboutBeing Topper
In Socials:
C++ PROGRAM FOR ACTIVITY SELECTOR25/05/2013Next

Related Posts

Information technologyYouTube

How to Apply Adsense on YouTube

I hope you are coming on this page to know about YouTube Adsense and how we can apply...

Being Topper 26/09/2017
B.tech notesBasic ProgramsBCA NOTESInformation technologyJava Programs

java program for checking prime number

checking prime number import java.util.Scanner ; class CheckPrime { public static void...

Being Topper 18/02/2014
Categories
Recent Posts
  • Best Email Marketing Software and Services
  • How to Apply Adsense on YouTube
  • Complete Guide to Writing a Newsletter !
  • Benefits of Creating Email List for small Businesses | Digital Marketing
  • Create Account or Get Email Alerts When New Employees Join a Company

Copyright © 2021 Being Topper ® . All Rights Reserved