worked on swap algorithm