printing first and last element before and after sorting the list