Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
39 changes: 23 additions & 16 deletions project/iterative_sorting.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
# Complete the selection_sort() function below in class with your instructor
def selection_sort( arr ):


def selection_sort(arr):
# loop through n-1 elements
for i in range(0, len(arr) - 1):
cur_index = i
smallest_index = cur_index
# TO-DO: find next smallest element
# (hint, can do in 3 loc)




# TO-DO: swap




# # (hint, can do in 3 loc)
for j in range(cur_index, len(arr)):
if arr[j] < arr[smallest_index]:
smallest_index = j
# TO-DO: swap
arr[cur_index], arr[smallest_index] = arr[smallest_index], arr[cur_index]

Choose a reason for hiding this comment

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

Nice job with the inline swapping syntax.

return arr

Choose a reason for hiding this comment

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

This works! Great job on this function.



# TO-DO: implement the Insertion Sort function below
def insertion_sort( arr ):


def insertion_sort(arr):
for i in range(1, len(arr)):
cur_index = i
while cur_index > 0 and arr[cur_index] < arr[cur_index - 1]:
temp = arr[cur_index - 1]
arr[cur_index - 1] = arr[cur_index]
arr[cur_index] = temp
cur_index -= 1
return arr

Choose a reason for hiding this comment

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

I'm happy to say you got this one working, too. Maybe today you can work on quicksort in the recursive file. 😄



# STRETCH: implement the Bubble Sort function below
def bubble_sort( arr ):


def bubble_sort(arr):

return arr


# STRETCH: implement the Count Sort function below
def count_sort( arr, maximum=-1 ):
def count_sort(arr, maximum=-1):

return arr
return arr
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,5 @@ While ***Quick Sort*** has "quick" in its name, it is typically not used as freq
- What programming languages use **Timsort** to implement their built-in `sort()` functions?
- If an interviewer asked you to describe the **Tim Sort** algorithm in 3-4 sentences, what would you say?
- Can you implement **Tim Sort** in Python?

PR: https://github.com/LambdaSchool/Sorting/pull/2