Whats the mistake?

  1. you need to enclose swap and increment statements after the else in a single block ( i.e inside {}).
  2. you need print each element in a new line so endl will come after cout<<a[i].