Implement the bubbleSortArray method that returns the array after sorting it using bubble sort logic.
The input contains an integer array nums and its length size. Your task is to sort the array in ascending order and return the sorted array.
Use the bubble sort idea: repeatedly compare adjacent values and swap them when they are in the wrong order. For example, [4,1,3,2] should become [1,2,3,4].
Bubble sort works by moving larger values toward the end of the array one step at a time.
During each pass, compare every adjacent pair. If the left value is greater than the right value, swap them. After one full pass, the largest unsorted value reaches its correct position at the end.
Repeat this process until all values are sorted. A swapped flag can stop the loop early when the array is already sorted.
Pseudocode:
function bubbleSortArray(nums, size):
for pass from 0 to size - 2:
swapped = false
for i from 0 to size - pass - 2:
if nums[i] > nums[i + 1]:
swap nums[i] and nums[i + 1]
swapped = true
if swapped == false:
break
return nums