Skip to content
Permalink
Browse files

recursive insertion sort working, hell fucking yeah

  • Loading branch information...
bcarlborg committed Apr 2, 2018
1 parent 97cbf86 commit 1a35daa4a7a9a19b7944ff7a9ddb531fcbda989c
Showing with 33 additions and 18 deletions.
  1. +33 −18 monkey_business.py
@@ -1,29 +1,44 @@
def return_list( N ):
my_list=list(range(12))
new_list = my_list[:]
return new_list
from random import *

print(return_list(10))
def single_insertion(input_list):
list_length = len( input_list )

if ( list_length == 1 ):
return input_list

def insertion_sort(input_list, element_to_add):
current_element_index = len(input_list) - 1
while element_to_add < input_list[current_element_index]:
current_element_index = current_element_index - 1
input_list.insert(current_element_index, element_to_add)
return input_list
else:
item_to_insert = input_list.pop()
sorted_sub_list = single_insertion( input_list )
sorted_sub_list.append(item_to_insert)

print('function input list', insertion_sort([1,3,4,10], 7))
index_of_item_to_insert = list_length - 1
index_of_comparison_item = index_of_item_to_insert - 1

while ( (sorted_sub_list[index_of_item_to_insert] < sorted_sub_list[index_of_comparison_item]) and (index_of_comparison_item >= 0) ):
temp = sorted_sub_list[index_of_comparison_item]
sorted_sub_list[index_of_comparison_item] = sorted_sub_list[index_of_item_to_insert]
sorted_sub_list[index_of_item_to_insert] = temp

index_of_item_to_insert -= 1
index_of_comparison_item -= 1
return sorted_sub_list

def worst_case_input_generator( input_size ):
pass
def worst_case_input_generator(number_of_inputs):
output_list = list( range(number_of_inputs) )
output_list.sort(reverse=True)
return output_list

def best_case_input_generator( input_size ):
pass
def best_case_input_generator(number_of_inputs):
output_list = list( range( number_of_inputs ) )
return output_list

def random_input_generator( input_size ):
pass
def random_input_generator(number_of_inputs):
output_list = []
for x in range( number_of_inputs ):
output_list.append( randint(1, number_of_inputs) )
return output_list


print( random_input_generator(20) )


0 comments on commit 1a35daa

Please sign in to comment.
You can’t perform that action at this time.