oday
07/12/2021, 12:29 PMhead ends up changing and pointing to new elements
https://paste.ofcode.org/3h6juagTuPwvZaDEeTkwCPoday
07/12/2021, 12:30 PModay
07/12/2021, 12:35 PMcurrent also reassign headoday
07/12/2021, 12:35 PModay
07/12/2021, 12:42 PMSourabh Rawat
07/12/2021, 3:09 PMhead is getting reassigned?oday
07/12/2021, 3:11 PMNode(2, Node(3, Node(4, Node(5))))oday
07/12/2021, 3:11 PModay
07/12/2021, 3:23 PMSourabh Rawat
07/12/2021, 3:25 PModay
07/12/2021, 3:27 PModay
07/12/2021, 3:31 PMfun main(){
val variable = 100
println(test(variable))
}
fun test(testValue: Int): Int {
var temp = testValue
temp = 98
return testValue
}
result should be 98 nowoday
07/12/2021, 3:33 PMSourabh Rawat
07/12/2021, 3:38 PMhead will never be changed, although it's next value can be changed(in the while loop). Since for removing duplicates you won't be removing the first element, only second and so on. thats why they are just returning head.
In fact, they don't even need to return the head from the function, as it will always refer to same node object as the passed head to the function.oday
07/12/2021, 3:41 PModay
07/12/2021, 3:42 PMhead, I added that myself because I thought how come it looks like a no-opoday
07/12/2021, 3:42 PM