Added function to sort an array