c++ vector bubble sort

You need to pass by reference; by making a copy, you sort a temporary copy, and then that’s it; it disappears and the original is still unsorted, because, once again, you sorted only a temporary copy of the entire vector. So change vector<int> a to vector<int>& a. Here’s the code, fixed: http://coliru.stacked-crooked.com/a/2f118555f585ccd5

Best Case for Bubble Sort

I want to know what will be the best case for a bubble sort ? There may be a case wherein there may be no swapping for the say last 2 passes for example. I’m doing my program in C language. Suppose i have an array of 5 elements and i give the elements as … Read more