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

Quicksort java #161

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
7 changes: 7 additions & 0 deletions bubble_sort/Python/Bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def bubble_sort(mas):
for i in range(len(mas)):
for j in range(len(mas) - 1, i, -1):
if mas[j] < mas[j-1]:
mas[j], mas[j-1] = mas[j-1], mas[j]
Copy link
Member

Choose a reason for hiding this comment

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

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpd1qdvjsf/bubble_sort/Python/Bubble_sort.py
+++ b/tmp/tmpd1qdvjsf/bubble_sort/Python/Bubble_sort.py
@@ -4,4 +4,6 @@
             if mas[j] < mas[j-1]:
                 mas[j], mas[j-1] = mas[j-1], mas[j]
     return mas
+
+
 print(bubble_sort([4, 3, 2, 1]))

return mas
print(bubble_sort([4, 3, 2, 1]))
Copy link
Member

Choose a reason for hiding this comment

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

E305 expected 2 blank lines after class or function definition, found 0

Origin: PycodestyleBear (E305), Section: all.autopep8.

51 changes: 51 additions & 0 deletions quicksort/Java/quicksort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.Scanner;

class QuickSortClass {
public static void sort(int[] arr)
{
quickSort(arr, 0, arr.length - 1);
}

public static void quickSort(int arr[], int low, int high)
{
int i = low, j = high;
int temp;
int pivot = arr[(low + high) / 2];

while (i <= j)
{
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;

i++;
j--;
}
}

if (low < j)
quickSort(arr, low, j);
if (i < high)
quickSort(arr, i, high);
}

public static void main(String[] args)
{
int[] input = {89,56,2,48,23,41,69,10};
System.out.println("Before Sorting : ");
for (int j = 0; j < input.length; j++) {
System.out.println(input[j]);}
sort(input);
System.out.println("==================");
System.out.println("After Sorting : ");
for (int i = 0; i < input.length; i++) {
System.out.println(input[i]);
}
}
}