Logic of Bubble sort