Interview Question: Fingering the End

Sample Question #318 (programming – C++)

How do you find out if a linked list has an end to it, i.e., not a loop?

Advertisements
This entry was posted in Sample Qs and tagged , , . Bookmark the permalink.

2 Responses to Interview Question: Fingering the End

  1. borland2ustc says:

    two pointer move with different speed.
    if they overlap some time, there is a loop

  2. Kevin says:

    Are we talking about single-linked lists or double-linked lists?

    Single: There exists a node without children, in which case there must be an end.
    Double: There exists a node with only one child, if any node has one child then there must be an end and not a loop.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s