oday
07/12/2021, 12:29 PMhead
ends up changing and pointing to new elements
https://paste.ofcode.org/3h6juagTuPwvZaDEeTkwCPcurrent
also reassign head
Sourabh Rawat
07/12/2021, 3:09 PMhead
is getting reassigned?oday
07/12/2021, 3:11 PMNode(2, Node(3, Node(4, Node(5))))
Sourabh Rawat
07/12/2021, 3:25 PModay
07/12/2021, 3:27 PMfun main(){
val variable = 100
println(test(variable))
}
fun test(testValue: Int): Int {
var temp = testValue
temp = 98
return testValue
}
result should be 98 nowSourabh 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 PMhead
, I added that myself because I thought how come it looks like a no-op