Hard to tell without saying what the actual error is.
At a glance, I'd imagine it's this line: if( a[j] > a[j+1]) swap<int,int>(a[j],a[j+1]);
In the fifth iteration of your loop (where j will be equal to 4) you're access a[j+1], which in this iteration is a[5].
Given that the array a has five elements, the highest element is a[4]. By trying to access a[5] you're trying to access an index that is out of the array bounds.