Skip to content
Open
Changes from all 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
38 changes: 30 additions & 8 deletions libs/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@
# Module to store various algorithms
#
# Author: XCC
# Date: 10/25/2020
#
# Date: 11/03/2020
# Edited by: Ayaan D.


def bubbleSort(list):
return list
def bubbleSort(ls):
lengthOfList = len(numList)
for i in range(lengthOfList):
for j in range(0, lengthOfList - i - 1):
if numList[j] > numList[j+1]:
numList[j], numList[j+1] = numList[j+1], numList[j]
Copy link

Choose a reason for hiding this comment

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

oh i forgot i could do that thingy on line 14

Copy link
Author

Choose a reason for hiding this comment

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

yeah i completely forgot about it as well. i learned sorting algos in java so doing them in python took me a lot longer than it should've lol

return ls


def insertionSort(list):
return list
def insertionSort(ls):
lengthOfList = len(numList)
for i in range(1, lengthOfList):
position = numList[i]
j = i-1
while j >= 0 and position < numList[j]:
numList[j+1] = numList[j]
j -= 1
numList[j+1] = position

return ls


def selectionSort(list):
return list
def selectionSort(ls):
lengthOfList = len(numList)
for i in range(lengthOfList):
indexOfMinimum = i
for j in range(i+1, lengthOfList):
if numList[indexOfMinimum] > numList[j]:
indexOfMinimum = j
numList[i], numList[indexOfMinimum] = numList[indexOfMinimum], numList[i]

return ls