Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Quick Sort Implementation

Objec­tive: Write an algo­rithm to sort an array in increas­ing or decreas­ing order using Quick Sort.

Input:  An Array arrA[]

Out­put: A sorted array.

Approach:

  • Choose any ele­ment from the array and call it as pivot ele­ment, Exam­ple here we have selected mid­dle ele­ment as pivot
  • Place all the ele­ments smaller than pivot in the left side of pivot.
  • Place all the ele­ments greater than pivot in the right side of pivot.
  • Sort left side and right side recursively.

Exam­ple:

Quick Sort Example

Quick Sort Example

Com­plete Code:

Output:
UnSorted : 2 1 8 4 0 9 3 11
Quick Sorted : 0 1 2 3 4 8 9 11

You may also like...