posted 11 years ago
so I had a question on stackoverflow on 2 different ways to implement a linked list and I sort of got my answer, but I need reassurance.
When creating a linked list class why do some people make 'head' the start of the list, while others make 'head' the current node of the list. In other words, in the first case head will always be the first position in the list, and so when implementing methods you must traverse the list. In the second case, head will always be the last node entered, so if I have 10 nodes than head is the 10th node, and when you add to it, you dont have to traverse the list.
I am so confused on why there exists these 2 different ways and which one to use, mainly for interviews. I am on day 3 of watching linked list videos over and over again and every tutorial does it differently and it is throwing me off. Also why do some singly linked lists have a head AND tail while most only have a head. I am currently viewing like 10 different linked list and they are all different..