Adding a Constructor
Being able to manually create nodes and link them together is fine, but it’s a bit of a pain and it’s easy to mess up. Instead, let’s make it so that we can instantiate a new
LinkedList object by passing in a list of strings, similar to how
It should take an optional parameter of
nodes, which is the list of strings the user can supply. If no
nodes list is supplied, then the linked list will start out as empty, just like before. First, we’ll check to see if the user supplied a list.
Become a Member to join the conversation.