Quick Sort in c++

#include <bits/stdc++.h> 
using namespace std;  
  
 
void swap(int* a, int* b)  
{  
    int t = *a;  
    *a = *b;  
    *b = t;  
}  
  

int partition (int arr[], int low, int high)  
{  
    int pivot = arr[high];  
    int i = (low - 1);  
  
    for (int j = low; j <= high - 1; j++)  
    {  
     
        if (arr[j] < pivot)  
        {  
            i++;  
            swap(&arr[i], &arr[j]);  
        }  
    }  
    swap(&arr[i + 1], &arr[high]);  
    return (i + 1);  
}  
  

void quickSort(int arr[], int low, int high)  
{  
    if (low < high)  
    {  
        
        int pi = partition(arr, low, high);  
   
        quickSort(arr, low, pi - 1);  
        quickSort(arr, pi + 1, high);  
    }  
}  
  

void printArray(int arr[], int size)  
{  
    int i;  
    for (i = 0; i < size; i++)  
        cout << arr[i] << " ";  
    cout << endl;  
}  
  

int main()  
{  
    int arr[] = {10, 7, 8, 9, 1, 5};  
    int n = sizeof(arr) / sizeof(arr[0]);  
    quickSort(arr, 0, n - 1);  
    cout << "Sorted array: \n";  
    printArray(arr, n);  
    return 0;  
}  

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c++ code for quick sort c++ stl quicksort quicksort algorithm cpp cpp quick sort quick sort function c++ quicksort c++ implementation quick sort in c++ using class quick sort implementation in c++ cpp program for quick sort quick sort example c++ quick sort c++ function quick sort c++ syntax quicksort in c++ using array quick sort in C + + statistics quick sort code in C plus plus quicksort c++ algoritm quicksort en c++ quick sort cpp geekforgeeks quick sort c++ stl c++ quick sort algorithm quick sort stl c++ quick sort example in c++ quick sort code c++ quicksort c++ complexity quicksort c++ program c++ quicksort algorithm quick sort in c++ stl quicksort c++ explained quick sort in cpp complexity how to do quicksort in c++ quicksort program c++ code for quick sort in cpp quick sort c++ algorithm code quicksort implementation c++ quick sort stl implementation of quick sort in c++ quicksort algorithm in c++ quick sort array c++ c++ quicksort function quick sort implementation c++ complexity quick sort using structure in c++ quick sorting in c++ algorithm to implement Quick Sort in c++ quick sort with cpp library quick sort with cpp quick sort cpp stl quick sort program CODE in c++ quicksort.cpp Quick Sort sort c++ code quick sort code cpp c++ array quick sort quicksort program in c++ quick sort algorithm in c++ quick sort implementation c++ quicksort function in C++ quick sort cpp quick sort algorithm c++ quick sort c++ implementation quicksort function c++ quick sort c++ with step by step quicksort c++ code example how to code quick sort in c++ quick sort c++ code quick sort code in c++ c++ program for quicksort Quicksort in cpp quick sort algorithm in cpp partition sort c++ quicksort divide and conquer quicksort cpp quicksort c++ partition sort in c quick sort without swapping function c++ quick sort pseudocode c++ quick sort c++ without using functions quick sorting algorithm c++ quick sort function in c++ quicksort c++ code quicksort gfg recursive quicksort algorithm c++ partition in quicksort c++ quick sort in cpp recursive quicksort quick sort in ascending order in c++ code quicksort code c++ Program for implementing quick sort in cpp quicksort in c++ with our own input quicksort in c++ quick sort program in cpp pivot array in c++ c++ quicksort Quick Sort in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source