/**
 * Geologists often work with coordinates to describe the location
 * of different geological features. In this exercise, you are given
 * a list of coordinates that are already sorted in ascending order.
 * Your task is to write a function that appends a new coordinate to
 * the list while ensuring that the list remains sorted. The new
 * coordinate should be inserted at the correct position in the list.
 *
 * @param coordinates A list of coordinates sorted in ascending order.
 * @param newCoord The new coordinate to be appended to the list.
 * @return The updated list of coordinates with the new coordinate added.
 */
fun appendSortedCoords(coordinates: MutableList<Double>, newCoord: Double): List<Double> {

    // Check if the provided list is empty
    if (coordinates.isEmpty()) {
        // If the list is empty, simply append the new coordinate
        coordinates.add(newCoord)
        return coordinates
    }

    // Find the correct position to insert the new coordinate
    var low = 0
    var high = coordinates.size - 1

    while (low <= high) {
        val mid = (low + high) / 2
        if (coordinates[mid] < newCoord) {
            low = mid + 1
        }
        // Add additional conditions here if needed
    }

    coordinates.add(low, newCoord)
    return coordinates
}
/**
 * Geologists often work with coordinates to describe the location
 * of different geological features. In this exercise, you are given
 * a list of coordinates that are already sorted in ascending order.
 * Your task is to write a function that appends a new coordinate to
 * the list while ensuring that the list remains sorted. The new
 * coordinate should be inserted at the correct position in the list.
 *
 * @param coordinates A list of coordinates sorted in ascending order.
 * @param newCoord The new coordinate to be appended to the list.
 * @return The updated list of coordinates with the new coordinate added.
 */
fun appendSortedCoords(coordinates: MutableList<Double>, newCoord: Double): List<Double> {
/**
 * Geologists often work with coordinates to describe the location
 * of different geological features. In this exercise, you are given
 * a list of coordinates that are already sorted in ascending order.
 * Your task is to write a function that appends a new coordinate to
 * the list while ensuring that the list remains sorted. The new
 * coordinate should be inserted at the correct position in the list.
 *
 * @param coordinates A list of coordinates sorted in ascending order.
 * @param newCoord The new coordinate to be appended to the list.
 * @return The updated list of coordinates with the new coordinate added.
 */
fun appendSortedCoords(coordinates: MutableList<Double>, newCoord: Double): List<Double> {

    // Check if the provided list is empty
    if (coordinates.isEmpty()) {
        // If the list is empty, simply append the new coordinate
        coordinates.add(newCoord)
        return coordinates
    }

    // Find the correct position to insert the new coordinate
    var low = 0
    var high = coordinates.size - 1

    while (low <= high) {
        val mid = (low + high) / 2
        if (coordinates[mid] < newCoord) {
            low = mid + 1
        }
        // Add additional conditions here if needed
    }

    coordinates.add(low, newCoord)
    return coordinates
}