Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick_sort.cpp: Add QuickSort C++ #255

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions quicksort/Cpp/quick_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant line

#include <iostream>

using std::cout;

void quick_sort(int a[], int left, int right) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]

Origin: CPPLintBear, Section: all.cpplint.

int i = left, j = right;
int pivot = a[right];

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]
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a ; after a } [readability/braces] [4]

Origin: CPPLintBear, Section: all.cpplint.


if (left < j)
quick_sort(a, left, j);
if (i < right)
quick_sort(a, i, right);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]

Origin: CPPLintBear, Section: all.cpplint.

}

int main(void){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before { [whitespace/braces] [5]

Origin: CPPLintBear, Section: all.cpplint.

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<a_size; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around = [whitespace/operators] [4]

Origin: CPPLintBear, Section: all.cpplint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around < [whitespace/operators] [3]

Origin: CPPLintBear, Section: all.cpplint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before ( in for( [whitespace/parens] [5]

Origin: CPPLintBear, Section: all.cpplint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before { [whitespace/braces] [5]

Origin: CPPLintBear, Section: all.cpplint.

cout << a[i] << " ";
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]

Origin: CPPLintBear, Section: all.cpplint.