0

Why I am able to modify values into set ?

Hi I am confused with code behaviour of below code : As far as I know , we can't change value of set elements as it is balanced tree as per implementation. One can modify value by erasing the same and adding again with required value.. Now this code allows modification of pRoot once it is inserted to set. Another question is my for loop has const reference by having const auto& p... Still it is allowing modification. Can someone please help me understand why so ? https://code.sololearn.com/c3sriB7wCQZb/?ref=app

12th Mar 2022, 8:51 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 ответов
+ 1
You didn't change the value of a set element. The set only consisted of a node pointer. The node pointer is a memory address that points to a node. This address didn't change, but the contents held at the address were modified.
12th Mar 2022, 9:20 AM
ChaoticDawg
ChaoticDawg - avatar
0
Thanks
12th Mar 2022, 10:37 AM
Ketan Lalcheta
Ketan Lalcheta - avatar