hiiii friends, please tell me
How do we find out if a linked-list has an end?
Printable View
hiiii friends, please tell me
How do we find out if a linked-list has an end?
The only logical way would be to traverse it and when the next pointer of the current element is null, it means that the current element is the last element.
I started to say that all linked lists have an end and a beginning... commonly known as a head and tail... but then I realized it's possible to have a circular linked list... where the tail points to the head... so it just goes around and around and around... if that's the case then you need to start somewhere, mark it, or some how store where you are... then go to the next item in the list... if you hit a NULL (or Nothing in VB) pointer to the next element, as Niya noted, you've reached the end. IF you have a circular list though and come back around to where you started, then... well, you have a circular list and there is no end.
-tg