quick sort in c 2b 2b

Solutions on MaxInterview for quick sort in c 2b 2b by the best coders in the world

showing results for - "quick sort in c 2b 2b"
Paola
01 Apr 2019
1#include <bits/stdc++.h> 
2using namespace std;  
3  
4 
5void swap(int* a, int* b)  
6{  
7    int t = *a;  
8    *a = *b;  
9    *b = t;  
10}  
11  
12
13int partition (int arr[], int low, int high)  
14{  
15    int pivot = arr[high];  
16    int i = (low - 1);  
17  
18    for (int j = low; j <= high - 1; j++)  
19    {  
20     
21        if (arr[j] < pivot)  
22        {  
23            i++;  
24            swap(&arr[i], &arr[j]);  
25        }  
26    }  
27    swap(&arr[i + 1], &arr[high]);  
28    return (i + 1);  
29}  
30  
31
32void quickSort(int arr[], int low, int high)  
33{  
34    if (low < high)  
35    {  
36        
37        int pi = partition(arr, low, high);  
38   
39        quickSort(arr, low, pi - 1);  
40        quickSort(arr, pi + 1, high);  
41    }  
42}  
43  
44
45void printArray(int arr[], int size)  
46{  
47    int i;  
48    for (i = 0; i < size; i++)  
49        cout << arr[i] << " ";  
50    cout << endl;  
51}  
52  
53
54int main()  
55{  
56    int arr[] = {10, 7, 8, 9, 1, 5};  
57    int n = sizeof(arr) / sizeof(arr[0]);  
58    quickSort(arr, 0, n - 1);  
59    cout << "Sorted array: \n";  
60    printArray(arr, n);  
61    return 0;  
62}  
queries leading to this page
quick sort algorithm in c 2b 2bquick sort c 2b 2b boostc 2b 2b quicksort functionquicksort c 2b 2b implementationquick sort function c 2b 2bquick sort example in c 2b 2bquick sort algorithm c 2b 2bquick sort code in c plus plusquicksort code c 2b 2bquick sort c 2b 2b syntaxquick sort c 2b 2b functionprogram for implementing quick sort in cppquicksort c 2b 2b codequick sort c 2b 2b implementationcpp quicksortquick sort code in c 2b 2bpartition sort in ccode for quick sort in cppquick sort in c 2b 2b statisticsquick sort program code in c 2b 2b quicksort function c 2b 2bimplement the quick sort algorithm c 2b 2bquicksort c 2b 2b explainedimplementation of quick sort in c 2b 2bquick sort cppc 2b 2b stl quicksortquicksort cppalgorithm quicksort c 2b 2bquick sort stl c 2b 2bquicksort c 2b 2bquick sort array c 2b 2bquicksort function in c 2b 2bquick sort in cpp modulequick sort c 2b 2b codequick sort code c 2b 2bcpp quick sortquicksort program in cppquick sort code in c 2b 2bc 2b 2b quicksortquicksort in c 2b 2bquick sort c 2b 2b algorithm libraryquick sort implementation in c 2b 2bquicksort c 2b 2b programc 2b 2b code for quick sortquick sorting in c 2b 2bquick sort struct cppquick sort cpp geekforgeeksquicksort gfg recursivequick sort stlquicksort program in c 2b 2bquick sort pseudocode c 2b 2bquicksort cppquicksort algorithm cppquick sorting algorithm c 2b 2bquick sort c 2b 2b with step by stepquick sort function in c 2b 2bquick sort in stlquicksort c 2b 2b complexityquicksort algorithm c 2b 2bwquicksort in c 2b 2b using arrayc 2b 2b quick sort functionquicksort en c 2b 2bquick sort algorithm in cpppartition in quicksort c 2b 2bquicksort divide and conquerquick sort cpp stlquick sort without swapping function c 2b 2brecursive quicksortc 2b 2b program for quicksortquick sort in cppcpp program for quick sortquick sort implementation c 2b 2bquick sort implementation c 2b 2b complexityhow to code quick sort in c 2b 2balgorithm to implement quick sort in c 2b 2bdoes stl sort use quick sortquick sort program in cpphow to do quicksort in c 2b 2bquicksort program c 2b 2bpivot array in c 2b 2bquick sort with cpp libraryquicksort implementation c 2b 2bquick sort in c 2b 2b stlc 2b 2b quicksort algorithmquicksort in cppc 2b 2b quick sort algorithmquicksort c 2b 2b code examplequick sort code cppquick sort with cppquick sort c 2b 2b stlquick sort in c 2b 2bquick sort algorithm cppquick sort array cppquick sort struct array cppquicksort in c 2b 2b with our own inputc 2b quicksortquick sort example c 2b 2bpartition sort c 2b 2bquick sort in c 2b 2b using classc 2b 2b array quick sortquicksort algorithm c 2b 2bquicksort c 2b 2b algoritmquick sort in ascending order in c 2b 2b codequicksort algorithm in c 2b 2bquick sort c 2b 2b algorithm quick sort c 2b 2b algorithm codequick sort c 2b 2b without using functionsquick sort in cppquick sort using structure in c 2b 2bquick sort sort c 2b 2b codequick sort in cpp complexityquick sort in c 2b 2b