Let's say we have disk of radius $0$,$5$,$1$,$4$,$3$,$2$
We have many disks, one above other, our task is to arrange them from largest disk to smaller disk.
The only operations available is, take a couple of disks from the top, hold it in your hand, rotate it & put it back.
Just imagine in a real scenario.
How we will do it.
$0$,$5$,$1$,$4$,$3$,$2$
What I will do is, I will take all plates from $5$ to $2$ $(5,1,4,3,2)$ I hold them in my hand, rotated my hand $180$ degree & put it back.
$0,2,3,4,1,5$
Now I will rotate all.
$5,1,4,3,2,0$
Now $5$ is at its right place. We will not consider it.
Now find the second largest plate... $4$.. rotate from $4$ to $0$
$5 \ | \ ,1,0,2,3,4$
rotate from $1$ to $4$.
$5,4 \ |,3,2,0,1$
Now $4$ is at its right place.
Next maximum is $3$, it is at its right place, so we may add one more line in the code to reduce steps...
Otherwise, the same algo will also keep $3$ at it's right place.
The same algo will sort them at last.
Hence, our algo is:
Step 1:
Find the current largest element.
Step 2:
Rotate the elements from largest element to end of the array. (Hold the disks from disk of max size to disk at top & rotate)
Step 3:
Now rotate the array from current start$+1$ to top.
Continue this process till it is sorted.
Note that initially current_start $= -1$ it will be incremented by one every time we get our largest disk placed at its correct place.