Implemented Sort to sort the output.