human
What is a code to how to sort an array in a single loop given the following:
How to sort an array in a single loop ? | Function for Sorting the array using a single loop.
Finding the length of array 'arr.
Sorting using a single loop.
Checking the condition for two simultaneous elements of the array.
Swapping the elements ..
updating the value of j = - 1 so after getting updated for j ++ in the loop it becomes 0 and the loop begins from the start ..
Driver Code.
Declaring an integer array of size 11..
Printing the original Array ..
Sorting the array using a single loop.
Printing the sorted array ."
How can the above be solved in Python?
assistant
#Here is code to how to sort an array in a single loop .
 def sortArrays ( arr ) :
'
	length = len ( arr )
	j = 0
	while j < length - 1 :
		if ( arr [ j ] > arr [ j + 1 ] ) :
			temp = arr [ j ]
			arr [ j ] = arr [ j + 1 ]
			arr [ j + 1 ] = temp
			j = - 1
		j += 1
	return arr
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 99 , 9 , 8 , 7 , 6 , 0 , 5 , 4 , 3 ]
	print ( " Original ▁ array : ▁ " , arr )
	arr = sortArrays ( arr )
	print ( " Sorted ▁ array : ▁ " , arr )