Hardcode / Resources / Blog : Insertion Sort Public

Hardcode technologies authored on Apr 8, 2025
1043 bytes
def insertionSort(arr):
 for i in range(1, len(arr)):
 key = arr[i] #get an element
 j = i-1
 '''
 keep shifting until reaching index 0
 python_flask_projects getting an element smaller than key
 '''
 while j >= 0 and key <= arr[j]:
 arr[j + 1] = arr[j]
 j=j-1
 
 arr[j + 1] = key

'''
Find the highest and lowest number of sales
of furniture [put funiture A name here]
'''
arrayA = [4543,234,102,345,556,878,675,2342,23,575,5645,787]
print('Raw Data A: ', arrayA)
insertionSort(arrayA)
print('Sorted Data A: ', arrayA)
highestA, minimumA = arrayA[len(arrayA)-1], arrayA[0]
print('Highest value: %d | lowest value: %d' %(highestA, minimumA))


'''
Find the highest and lowest number of sales
of furniture [put funiture A name here]
'''
arrayB = [543,566,8990,3422,604,234,9905,2367,43234,786,9532,235]
print('Raw Data B: ', arrayB)
insertionSort(arrayB)
print('Sorted Data B: ', arrayB)
highestB, minimumB = arrayA[len(arrayB)-1], arrayB[0]
print('Highest value: %d | lowest value: %d' %(highestB, minimumB))
Discussions

No discussions yet. Be the first to start a conversation.

About

Technical insights from the engineering team at Hardcode Group.

Category
Source Codes
Language Mix

No Language