Skip to content

Commit 117de26

Browse files
added in place and out of place solves
1 parent 0f496ab commit 117de26

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function selectionSort(arr) {
5353
```
5454

5555
```python
56-
def selection_sort(list):
56+
def selection_sort_out_of_place(list):
5757
sorted_list = []
5858

5959
while len(list) > 0:
@@ -65,6 +65,24 @@ def selection_sort(list):
6565
return sorted_list
6666
```
6767

68+
```python
69+
def selection_sort_in_place(list):
70+
for i in range(len(list)):
71+
min_element = list[i]
72+
min_element_index = i
73+
74+
for j in range(i + 1, len(list)):
75+
if list[j] < min_element:
76+
min_element = list[j]
77+
min_element_index = j
78+
79+
temp_element_0 = list[i]
80+
list[i] = min_element
81+
list[min_element_index] = temp_element_0
82+
83+
return list
84+
```
85+
6886
Use the language of your choosing. We've included starter files for some
6987
languages where you can pseudocode, explain your solution and code.
7088

0 commit comments

Comments
 (0)