Modified swap function to use pointer notation