formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -33,17 +33,14 @@
*
*/
int partition(int arr[], int low, int high)
{
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // taking the last element as pivot
int i = (low - 1); // Index of smaller element
for (int j = low; j < high; j++)
{
for (int j = low; j < high; j++) {
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot)
{
if (arr[j] <= pivot) {
i++; // increment index of smaller element
int temp = arr[i];
arr[i] = arr[j];
@@ -62,10 +59,8 @@ int partition(int arr[], int low, int high)
* low --> Starting index,
* high --> Ending index
*/
void quickSort(int arr[], int low, int high)
{
if (low < high)
{
void quickSort(int arr[], int low, int high) {
if (low < high) {
int p = partition(arr, low, high);
quickSort(arr, low, p - 1);
quickSort(arr, p + 1, high);
@@ -73,15 +68,13 @@ void quickSort(int arr[], int low, int high)
}
// prints the array after sorting
void show(int arr[], int size)
{
void show(int arr[], int size) {
for (int i = 0; i < size; i++) std::cout << arr[i] << " ";
std::cout << "\n";
}
/** Driver program to test above functions */
int main()
{
int main() {
int size;
std::cout << "\nEnter the number of elements : ";
@@ -91,8 +84,7 @@ int main()
std::cout << "\nEnter the unsorted elements : ";
for (int i = 0; i < size; ++i)
{
for (int i = 0; i < size; ++i) {
std::cout << "\n";
std::cin >> arr[i];
}