Why can't we use the link in the algorithms and data structure?

Typically, use references in function parameters and return types to define attractive interfaces. Use pointers to implement algorithms and data structures.

I read this line in an article. I have doubts about why a link cannot be used in algorithms and data structures?

Please help me figure out why this is.

+4
source share
1 answer

Because a link cannot be made to refer to any other object after it has been initialized to refer to a specific one.

ยง8.5.3.2 of the Standard states as evidence

A link cannot be changed to refer to another object after initialization. Note that link initialization is handled very differently from the destination to it. Passing the argument (5.2.2) and Returning the value of the function (6.6.3) is initialization.

Data structures and algorithms (albeit to a lesser extent) typically include adding, deleting, and reordering objects within themselves. Using links you cannot do this, so use pointers to do this inexpensively.

+7
source

All Articles