But If there is no loop in the original list then this code will give
incorrect result.
the algo should hav been somethin like
if loopispresent
return the looping node
else
return NULL
--~--~-~--~~~---~--~~
You received this message becaus
:-S
On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote:
>
> This is the right one, with the correction. temp1 -> temp.
> By the way aakash, that point was a good one.
>
> On 4/4/07, Dhruva Sagar < [EMAIL PROTECTED]> wrote:
> >
> > Based on aakash's explanation there is another solution (similar to
This is the right one, with the correction. temp1 -> temp.
By the way aakash, that point was a good one.
On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote:
>
> Based on aakash's explanation there is another solution (similar to point
> no 2.)
>
> Traverse the link list and keep nulling the pointer
Based on aakash's explanation there is another solution (similar to point no
2.)
Traverse the link list and keep nulling the pointers in the link list. When
you reach the end, the last node you reach to is the node where the looping
is occurring.
Node*findLoopingNode(Node*start) {
Node*temp=sta
There are many efficient ways to do this. I am listing them out.
1) Use two pointers. One advancing one node at a time and the other
advancing 2 nodes at a time. So that the relative speed between them is
always one node. If the first and second pointer coincide then there is a
loop.
2) Destructi
An alternate solution may be something like this:
You have two loops. one inside another.
node*temp1=start,*temp2=start;
node*loopingNode=null;
while(temp1) {
while(temp2) {
if(temp1->next=temp2->next) {
loopingNode=temp1->next;
break;
}
temp2=temp2->n
That's one solutionbut I am having memory constraintso need some
optimized algo
On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote:
>
> Yes and hence i mentioned that it would be better if you have a unique key
> such as an index as a property of the node itself. For example the info part
>
Yes and hence i mentioned that it would be better if you have a unique key
such as an index as a property of the node itself. For example the info part
of the node may have a index.
Then you could add that unique key to an array and check and compare that to
determine if a node is being traversed
It will consume lot of memory (varying on the length of link list).
On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote:
>
> I guess you can keep an array of node pointers where you could add the
> addresses of the nodes as you traverse through the link list. And you could
> loop through the arr
I guess you can keep an array of node pointers where you could add the
addresses of the nodes as you traverse through the link list. And you could
loop through the array to match the current node to the traversed nodes. If
there is a match it means that you are encountering that node again and
henc
Which data structure will be used to keep track of unique identifier?
We are not allowed to modify the struct node of linked list
On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote:
>
> It would be easy to do in case there is a unique identifier for each node.
> Simply traverse through the link li
It would be easy to do in case there is a unique identifier for each node.
Simply traverse through the link list and when you encounter a node twice it
means that the link list is looping at that node.
On 4/4/07, Pradeep Juneja <[EMAIL PROTECTED]> wrote:
>
>
>
> How can we know at what node, list
12 matches
Mail list logo