While defining LinkedList data structure in python, we are defining two separate classes - NodeClass and LinkedListClass. In the LinkedListClass, we only initiate/define ‘header’. Can’t we simply define a single class, and initiate/define ‘header’ in the same class as ‘data’ and ‘next’?
It is totally up to personal coding preferences. Both ways are fine. We can define a separate class for
Node as well as define a single class of
LinkedList containing the
Node method. However, defining separate classes makes the code base look cleaner and easier to read and debug when the complexity of the code base increases.
Hope this helps!