Insertion Sort (Array)
Python
def insertionSort(list):
for i in range(len(list)):
index=i
item = list[i]
while index>0 and item<list[index-1]:
list[index]=list[index-1]
index-=1
list[index]=item
return list
Java
public void insertionSort(int[] nums){
for(int i=0; i<nums.length; i++){
int index=i;
int item=nums[i];
while(index>0 && item<nums[index-1]){
nums[index] = nums[index-1];
index--;
}
nums[index] = item;
}
}