469,898 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Problem moving between nodes of a linked list

In single/double linked list having 10 nodes due to some memory problems the 4th next node is pointing to 3rd node not to a 5 th node, how to findout the 5th node?
please explain concept and send code .
Sep 24 '07 #1
4 1650
gpraghuram
1,275 Expert 1GB
In single/double linked list having 10 nodes due to some memory problems the 4th next node is pointing to 3rd node not to a 5 th node, how to findout the 5th node?
please explain concept and send code .
HI,
If there is a corruption then try to solve the issue first. and then this issue will be solved automatically.
Try to use some tool like Rational Purify to identify the memory corruption

Raghuram
Sep 24 '07 #2
ashitpro
542 Expert 512MB
This is what we called as loop in link list.
To find out loop in link list follow the steps.

take two pointers, pointing to start of link list.
while(first node != NULL && second node !=NULL)
{
advance first pointer with one node
advance first pointer with two node
if(first node == second node)
{
here you can say that, there is loop in link list
break
}
}
Sep 24 '07 #3
sicarie
4,677 Expert Mod 4TB
FYI - I changed the title of the thread to be a bit more descriptive.
Sep 24 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
This is what we called as loop in link list.
To find out loop in link list follow the steps.

take two pointers, pointing to start of link list.
while(first node != NULL && second node !=NULL)
{
advance first pointer with one node
advance first pointer with two node
if(first node == second node)
{
here you can say that, there is loop in link list
break
}
}
That's not going to work.

A loop in a linked list is when more than one node points at a second node.

What to have to do is start going through the list keeping a list of the current node addresses. If any node next address points to any address in the address list, you have a loop.

Before this, however, fix your linked list code.

I assume you are using C. If you ae using C++ you should be using the list template instead of re-inventing the wheel.
Sep 24 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by John N. | last post: by
3 posts views Thread by sugaray | last post: by
10 posts views Thread by Ben | last post: by
11 posts views Thread by bofh1234 | last post: by
4 posts views Thread by Niks | last post: by
2 posts views Thread by sieg1974 | last post: by
4 posts views Thread by Jonas Ferreira | last post: by
12 posts views Thread by kalyan | last post: by
6 posts views Thread by Gaijinco | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.