Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
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..
Everything in computer science involves trade-offs. having a 'head' and a 'tail' involves (slightly) more memory, more complexity, and more maintenance, but gives you flexibility in how you use your list.
Having the head always point to the last element entered speeds up the insertion, but at the cost of not preserving the order - i.e. you now have a LIFO rather than a FIFO. That may be OK for some applications, but not for others.
Which to use always depends on the specific case where you will be needing it - there is no "THIS is ALWAYS the right way to do it" answer in CS, ever.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors