what you've written is called a
bubble sort. it is called this because it will "bubble" values towards the end of the list.
here's the generally accepted take on bubble sort
advantages:
easy to write
very little memory overhead
disadvantages:
not the most intuitive algorithm
terrible big-o of n^2, and an omega of n^2 as well
the big-o of n^2 cannot be solved, however, the omega can be if you make a few optimizations to the sort.
the first optimization that can be made is checking to see if swaps were made after each pass on the list. if no swaps were made, then the list is sorted, and no further passes are required.
the second optimization which can be made to the algorithm affects the internal for loop. if you have a list of size n, and the number of passes you have already made on the list, i, then, for every pass you make on the list, the n-i'th element will be placed properly in the list, and there is no need for the algorithm to look at that last item again. in your case, you will need to set the condition of the inner for loop to run from indexes 0 to 2-i.
after these optimizations have been made, the algorithm should have an omega of simply, n.
sorts that are similar to bubble sort, which you might be interested in looking into are
insertion sort and
selection sortthose sorts are more intuitive meaning they function more like a human would actually sort a list of numbers.