While browsing old code I had written in freshman year of college, I found the following snippet marked as 'bubble sort'. (here n is the size of the array; eg. for an array of 10 elements n = 10).
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++) {
if(arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Now, i can tell that this certainly isn't bubble sort, but maybe a very poor implementation of it. Fact is it works and I'm curious if this is an algorithm that already exists or if it is something that I came up on my own albeit it being very inefficient.
1ton-j(which would ben-ihere), and the comparison is between[i]and[i-1], not[i]and[j]. If what you mean is that there are two (nested) loops and a swap, then I've got news for you: a whole lot of sorting algorithms match that description.