I am trying to make a function bubbleSort() that takes a mutable list of x(given by user) indexes as a parameter. So far the program is as follows:
The following code cannot be modified:
fun main(args: Array<String>) {
var list = mutableListOf<Int>()
print("Please Enter the Total Number of Elements :")
var number = readLine()!!.toInt()
for (i in 1..number) {
print("Please enter the $i Element :")
var value = readLine()!!.toInt()
list.add(value)
}
val sorted = bubbleSort(list)
println("The Sorted List in Ascending Order : $sorted")
}
Any change/addition must be included inside the bubbleSort() function after main().
I am struggling to understand how to pass the list with total x indexes and certain y values in each index into the bubbleSort() function. Please any feedback on how to start or a hint would be much appreciated. I am completely new to Kotlin and sorry for any misunderstanding on my question as English language is not my native.
I am aware of the logic in bubble sorting array(s). My main issue is the syntax in Kotlin and the fact I could not find sufficient sources online that could assist me on this main question (How to pass a mutable list as a parameter of a function).
CodePudding user response:
fun bubbleSort(list: MutableList<Int>) {
}