The bubble sort works by passing sequentially over a list, comparing each value to the one immediately after it. If the first value is greater than the second, their positions are switched. Over a number of passes, at most equal to the number of elements in the list, all of the values drift into their correct positions. Because each pass finds the maximum item and puts it at the end, the portion of the list to be sorted can be reduced at each pass.
The code for the sort is as follows:
using namespace std;
cout<<"enter the size of array (max 50)";
cout<<"n enter the array";
cout<<"n sorted array is";