-
Notifications
You must be signed in to change notification settings - Fork 302
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
Implemented the selection sort algo using python and java #473
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import java.util.Random; | ||
|
||
/* | ||
____ _ _ _ ____ _ | ||
/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Java/SelectionSort.java
+++ b/tmp/tmpz6y7xvz3/selection_sort/Java/SelectionSort.java
@@ -2,7 +2,7 @@
/*
____ _ _ _ ____ _
-/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
+/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __|
___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__| |
||
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __| | ||
___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Java/SelectionSort.java
+++ b/tmp/tmpz6y7xvz3/selection_sort/Java/SelectionSort.java
@@ -4,7 +4,7 @@
____ _ _ _ ____ _
/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __|
- ___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
+ ___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__|
*/ |
||
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__| | ||
|
||
*/ | ||
|
||
public class SelectionSort { | ||
|
||
public static void main(String[] args) { | ||
int[] unsortedArray = createRandomArray(40); | ||
int[] sortedArray = sort(unsortedArray); | ||
printArray(sortedArray); | ||
} | ||
|
||
private static int[] sort(int[] a) { | ||
int maxIdx = a.length - 1; | ||
for (int idx = 0; idx < maxIdx; idx++) { | ||
int minIdx = idx; | ||
for (int i = idx + 1; i <= maxIdx; i++) { | ||
if (a[i] < a[minIdx]) | ||
minIdx = i; | ||
} | ||
|
||
//swap | ||
int tmp = a[idx]; | ||
a[idx] = a[minIdx]; | ||
a[minIdx] = tmp; | ||
} | ||
return a; | ||
} | ||
|
||
private static int[] createRandomArray(int length) { | ||
int[] array = new int[length]; | ||
Random rand = new Random(); | ||
for (int i = 0; i < array.length; i++) | ||
array[i] = rand.nextInt(1000); | ||
return array; | ||
} | ||
|
||
private static void printArray(int[] array) { | ||
System.out.printf("[ "); | ||
for (int i = 0; i < array.length; i++) { | ||
System.out.print(array[i]); | ||
if (i < array.length - 1) | ||
System.out.print(", "); | ||
} | ||
System.out.printf(" ]"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
''' | ||
____ _ _ _ ____ _ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -1,5 +1,5 @@
'''
- ____ _ _ _ ____ _
+ ____ _ _ _ ____ _
/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __|
___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W291 trailing whitespace Origin: PycodestyleBear (W291), Section: |
||
/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -1,6 +1,6 @@
'''
____ _ _ _ ____ _
-/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
+/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __|
___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W291 trailing whitespace Origin: PycodestyleBear (W291), Section: |
||
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __| | ||
___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -2,7 +2,7 @@
____ _ _ _ ____ _
/ ___| ___| | ___ ___| |_(_) ___ _ __ / ___| ___ _ __| |_
\___ \ / _ | |/ _ \/ __| __| |/ _ \| '_ \\___ \ / _ \| '__| __|
- ___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
+ ___) | __| | __| (__| |_| | (_) | | | ___) | (_) | | | |_
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__|
''' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W291 trailing whitespace Origin: PycodestyleBear (W291), Section: |
||
|____/ \___|_|\___|\___|\__|_|\___/|_| |_|____/ \___/|_| \__| | ||
|
||
''' | ||
# author: john2ksonn | ||
# date: 10.28.2018 | ||
|
||
import random | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not comply to PEP8. Origin: PEP8Bear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -10,6 +10,7 @@
# date: 10.28.2018
import random
+
def sort(a):
max_idx = len(a) - 1 |
||
def sort(a): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E302 expected 2 blank lines, found 1 Origin: PycodestyleBear (E302), Section: |
||
max_idx = len(a) - 1 | ||
for idx in range(0, max_idx): | ||
min_idx = idx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -14,7 +14,7 @@
def sort(a):
max_idx = len(a) - 1
for idx in range(0, max_idx):
- min_idx = idx
+ min_idx = idx
for i in range(idx+1, max_idx+1):
if a[i] < a[min_idx]:
min_idx = i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not comply to PEP8. Origin: PEP8Bear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -14,7 +14,7 @@
def sort(a):
max_idx = len(a) - 1
for idx in range(0, max_idx):
- min_idx = idx
+ min_idx = idx
for i in range(idx+1, max_idx+1):
if a[i] < a[min_idx]:
min_idx = i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W291 trailing whitespace Origin: PycodestyleBear (W291), Section: |
||
for i in range(idx+1, max_idx+1): | ||
if a[i] < a[min_idx]: | ||
min_idx = i | ||
a[idx], a[min_idx] = a[min_idx], a[idx] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -18,7 +18,7 @@
for i in range(idx+1, max_idx+1):
if a[i] < a[min_idx]:
min_idx = i
- a[idx], a[min_idx] = a[min_idx], a[idx]
+ a[idx], a[min_idx] = a[min_idx], a[idx]
return a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not comply to PEP8. Origin: PEP8Bear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -18,9 +18,9 @@
for i in range(idx+1, max_idx+1):
if a[i] < a[min_idx]:
min_idx = i
- a[idx], a[min_idx] = a[min_idx], a[idx]
+ a[idx], a[min_idx] = a[min_idx], a[idx]
return a
-
+
if __name__ == "__main__":
rand_list = random.sample(range(1000), 40) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W291 trailing whitespace Origin: PycodestyleBear (W291), Section: |
||
return a | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
+++ b/tmp/tmpz6y7xvz3/selection_sort/Python/selection_sort.py
@@ -20,7 +20,7 @@
min_idx = i
a[idx], a[min_idx] = a[min_idx], a[idx]
return a
-
+
if __name__ == "__main__":
rand_list = random.sample(range(1000), 40) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293 blank line contains whitespace Origin: PycodestyleBear (W293), Section: |
||
|
||
if __name__ == "__main__": | ||
rand_list = random.sample(range(1000), 40) | ||
sorted_list = sort(rand_list) | ||
print(sorted_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
Origin: SpaceConsistencyBear, Section:
all.pyjava
.The issue can be fixed by applying the following patch: