Skip to content

Commit

Permalink
Merge pull request #2521 from CoderGhost37/kushagra
Browse files Browse the repository at this point in the history
Update contributorsList.js & added Quick_Sort.js
  • Loading branch information
fineanmol authored Oct 5, 2022
2 parents 5b0dbb4 + 102d4b4 commit 2552c1b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Program's_Contributed_By_Contributors/C++/Quick_Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// C++ program for implementation of Quick sort
#include <bits/stdc++.h>
using namespace std;

// Partition function
int partition(int arr[], int low, int high)
{
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element

for (int j = low; j <= high - 1; j++) {
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot) {
i++; // increment index of smaller element
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return (i + 1);
}

// A function to implement quick sort
// Time Complexity: O(nlogn)
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
// pi is partitioning index, arr[p] is now
// at right place
int pi = partition(arr, low, high);

// Separately sort elements before
// partition and after partition
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}

// Function to print an array
void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}

// Driver code
int main()
{
int arr[] = { 5, 1, 4, 2, 8};
int N = sizeof(arr) / sizeof(arr[0]);
quickSort(arr, N);
cout << "Sorted array: \n";
printArray(arr, N);
return 0;
}
5 changes: 5 additions & 0 deletions contributors/contributorsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1840,4 +1840,9 @@ contributors = [
fullname: "Sabin Thapa",
username: "https://github.com/sabin-thapa",
},
{
id:368,
fullname: "Kushagra Mathur",
username: "https://github.com/CoderGhost37",
},
];

0 comments on commit 2552c1b

Please sign in to comment.