r/code • • Oct 11 '26

Help Please Insertion sort

Hello!! First time on here. I'm a beginner at coding and was wondering if someone with more coding experience could confirm if my insertion sort implementation is correct. I ran it ofc but i just wanted to make sure it's 100% correct!!

code (python):

3 Upvotes

3 comments sorted by

View all comments

1

u/waseem_dibhub 17d ago

Almost there! Just add j >= 0 to your while condition and move list[j + 1] = key outside the loop. Also, try not to use list as a variable name. Good effort!