The list is virtually split into a sorted and an unsorted part. Value from the unsorted part is picked and placed at the correct position in the sorted part.
It stores the elements to be sorted in a list named "arr".
Assuming that the first element (at location 1) is already sorted.
Pick the next element and store it separately in a "key".
Compare the "key" with all elements in the sorted list.
If the element in the sorted list is smaller than the current element, then move to the next element. else, shift greater elements in the list towards the right.
Insert the "key" at proper location.
Repeat steps 4, 5 and 6 until the list becomes sorted.
Print the sorted list.
Simulator Procedure
Select the variables from the dropdown list.
Click on the Finish button or Start button to view the state diagram.
If you have clicked on the Start button then use Next and Previous button to view the State diagram.
Click on the Reset button when the State diagram is completed.