I am preparing for job interviews and was going over the implementation of a linked list. specifically appending to the end of the list.
when I initially wrote it out I had a public variables that held a pointer to the first node, and the last. so adding was simple, take the last node->next = newNode and the last node = newNode.
badabing bada boom.
i was looking up other peoples implementations, and every single one's(including wikipedia, which as we all know is always right) did not have a last node variable, but instead looped through the list until the tempNode->next ==NULL, and then that is your last one.
Logically the latter implementation makes sense but I cant see a reason for doing it. the small space the last pointer takes up, and the extra code to read and write to it, is still far less than having to loop through a list of 1000+ elements.
So, I figure I'm misunderstanding something. any help is appreciated.