The bubbleSort algorithm compares two numbers in an array and swaps them if the larger number is on the left. It repeats this until it doesn’t swap at all which would indicate that the array is sorted in least to greatest order.
The swap algorithm takes in an array of values and two integers (each indicating a different address in the array) switches the two variables values and returns the array with the two values swapped.
The bubbleSort algorithm relies on the swap function in order to do its job properly. The whole concept of bubbleSort revolves around its ability to swap to values based on certain conditions. The swap function could theoretically have a use in any function but it was specially created for this one.