diff --git a/README.md b/README.md index bedd8b06..1c0d18cc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Gitter](https://badges.gitter.im/NITSkmOS/algo.svg)](https://gitter.im/NITSkmOS/algo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![NITSkmOS Algorithms](https://img.shields.io/badge/NITSkmOS-Algorithms-blue.svg)](https://github.com/NITSkmOS/Algorithms) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/29024673e94b48459809432cdd280e39)](https://app.codacy.com/app/NITSkmOS/Algorithms?utm_source=github.com&utm_medium=referral&utm_content=NITSkmOS/Algorithms&utm_campaign=Badge_Grade_Settings) +[![Build Status](https://travis-ci.com/NITSkmOS/Algorithms.svg?branch=master)](https://travis-ci.com/NITSkmOS/Algorithms) [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/NITSkmOS/Algorithms/blob/master/LICENSE) diff --git a/bubble_sort/Cpp/bubble_sort.cpp b/bubble_sort/Cpp/bubble_sort.cpp index 7afbf06d..44f9a352 100644 --- a/bubble_sort/Cpp/bubble_sort.cpp +++ b/bubble_sort/Cpp/bubble_sort.cpp @@ -1,4 +1,5 @@ -#include +#include +using namespace std; void swap(int *xp, int *yp) { int temp = *xp; @@ -17,8 +18,6 @@ void bubble_sort(int arr[], int n) { swapped = true; } } - - // If no two elements were swapped by inner loop, then break if (swapped == false) break; } @@ -28,9 +27,8 @@ void bubble_sort(int arr[], int n) { void print_array(int arr[], int size) { int i; for (i = 0; i < size; i++) - printf("%d ", arr[i]); - - printf("\n"); + cout << arr[i] << " "; + cout << endl; } // Driver program to test above functions @@ -38,7 +36,7 @@ int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr) / sizeof(arr[0]); bubble_sort(arr, n); - printf("Sorted array: \n"); + cout << "Sorted array: " << endl; print_array(arr, n); return 0; } diff --git a/quicksort/Cpp/quick_sort.cpp b/quicksort/Cpp/quick_sort.cpp index 3ac2dbaf..823b0381 100644 --- a/quicksort/Cpp/quick_sort.cpp +++ b/quicksort/Cpp/quick_sort.cpp @@ -1,42 +1,39 @@ - #include using std::cout; void quick_sort(int a[], int left, int right) { + int i = left, j = right; + int pivot = a[right]; - int i = left, j = right; - int pivot = a[right]; - - while (i <= j) { + while (i <= j) { while (a[i] < pivot) i++; //carry on, this part already sorted while (a[j] > pivot) j--; //carry on, this part already sorted if (i <= j) { // a[i]>=pivot and a[j]<=pivot - //swap a[i] with a[j] + //swap a[i] with a[j] int tmp = a[i]; a[i] = a[j]; a[j] = tmp; i++; j--; } - }; + } - if (left < j) + if (left < j) quick_sort(a, left, j); - if (i < right) + if (i < right) quick_sort(a, i, right); - } -int main(void){ +int main(void) { int a[10] = { 10, 7, 9, 4, 6, 2, 5, 6, 84, 12}; int a_size = sizeof(a)/sizeof(a[0]); quick_sort(a, 0, a_size-1); - for(int i=0; i