In some programming languages, many data structures use Node<T>
(The examples in the question are in Java, but I suppose they are similar in other languages):
public class Node<T> {
T info;
Node<T> next;
...
I have seen students stare at the board\screen, perplexed, whenever this is introduced. They are confused by this implementation, because it is "Defining something with itself" (like saying "white is the color of things that are white-hot").
They have difficulty understanding how a class can have a property of itself. How could I explain to them why this is valid in programming?
This issue makes it hard for them to understand data structures like List
,Queue
etc.
Context: they are high-school students learning java, and are familiar with primitive types and a bit of OOP.
T
, it's theNode
field of theNode
class which is difficult for the students. $\endgroup$