My profesor added this line of code to a bubble sort saying that it made it more efficient by tracking the last swap. I don't understand how this would work
void bubble_sort(int a[], int n){
while (0<n-1) {
int last =0;
for (int i=0; i<n-1; i++) {
if (a[i]>a[i+1]) {
swap(a[i],a[i+1])
last=i;//this line tracks the last swap, but how would it stop the program once it is sorted?
}
}
}
}