word swap algorithm without string lib