/**
 * This exercise requires you to use the range function with lists and append new elements.
 *
 * Given a list of numbers and a new element, your task is to append the new element to the list
 * using the range function. Add the element to the middle of the list, such that the resulting
 * list is in ascending order.
 *
 * @param numbers A list of numbers in ascending order
 * @param element A new number to be added to the list
 * @return The modified list with the new element added to the middle
 */
fun addElementToList(numbers: MutableList<Int>, element: Int): List<Int> {

    // Find the index to insert the new element
    var index = numbers.size / 2

    // Iterate through a range to find the correct position
    for (i in numbers.indices) {
        if (numbers[i] > element) {
            index = i
            break
        }
    }

    // Insert the new element to the list
    numbers.add(index, element)

    return numbers
}
/**
 * This exercise requires you to use the range function with lists and append new elements.
 *
 * Given a list of numbers and a new element, your task is to append the new element to the list
 * using the range function. Add the element to the middle of the list, such that the resulting
 * list is in ascending order.
 *
 * @param numbers A list of numbers in ascending order
 * @param element A new number to be added to the list
 * @return The modified list with the new element added to the middle
 */
fun addElementToList(numbers: MutableList<Int>, element: Int): List<Int> {
/**
 * This exercise requires you to use the range function with lists and append new elements.
 *
 * Given a list of numbers and a new element, your task is to append the new element to the list
 * using the range function. Add the element to the middle of the list, such that the resulting
 * list is in ascending order.
 *
 * @param numbers A list of numbers in ascending order
 * @param element A new number to be added to the list
 * @return The modified list with the new element added to the middle
 */
fun addElementToList(numbers: MutableList<Int>, element: Int): List<Int> {

    // Find the index to insert the new element
    var index = numbers.size / 2

    // Iterate through a range to find the correct position
    for (i in numbers.indices) {
        if (numbers[i] > element) {
            index = i
            break
        }
    }

    // Insert the new element to the list
    numbers.add(index, element)

    return numbers
}