|
-
May 27th, 2013, 10:52 PM
#1
Thread Starter
Banned
How do we find out if a linked-list has an end?
hiiii friends, please tell me
How do we find out if a linked-list has an end?
-
May 28th, 2013, 02:45 AM
#2
Re: 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.
-
May 28th, 2013, 08:44 AM
#3
Re: How do we find out if a linked-list has an end?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|