EDIT: You're going to laugh when you see it, and I'm not too proud to admit that I looked at it longer than I should have (and even started writing it down) before I said, "Oh my God..." It's pretty humorous, when you see it.
But you should really look into vector. This entire thing could have been summed up:
Yeah, it's really simple. Far simpler than dealing with arrays.
And if you're still not sure where the mistake is, take a look at your swap function. Ask yourself, "What values do I want to swap?" then look at the values in the swap function and ask yourself what values are ACTUALLY being swapped.