Thanks a lot for this tutorial, When I had studied this, I was not serious at all. Thanks for brushing up the concept.

I like to add one more line to this explanation.

After completion of every inner loop, the last element get sorted(which is the sole of bubble sort), which the author have mentioned somewhat about this when he is calculating the efficiency.

for(int i=1;i<N;i++)
                if(S[i-1] > S[i])
                    int temp = S[i-1];
                    S[i-1] = S[i];
                    S[i] = temp;
                    swapped = true;
Also the c++ code misses the closing "{" .