shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
But I see an error. It just cycles through all the element without doing anything. In the process of cycle it changes the linker as you are looping one time less than total nodes.
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
I have another question. If i remove all the nodes in the linked list, how would i go about actually displaying that there's nothing left?
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
Quote:
Originally Posted by shabbir
But I see an error. It just cycles through all the element without doing anything. In the process of cycle it changes the linker as you are looping one time less than total nodes.
Ok where exactly do you see that?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by coolio2006
I have another question. If i remove all the nodes in the linked list, how would i go about actually displaying that there's nothing left?
If counter is zero output a message
Quote:
Originally Posted by coolio2006
Ok where exactly do you see that?
In the loop I pointed out.
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
I have a slight issue yet again. The code is:

Code:
for (int z = 1; z <= length; z++)
{
if (longlinker -> longlink -> num == number)
{
longlinker -> longlink -> num = number;
}
else
{
longlinker = longlinker -> shortlink;
}
Now, assume the linked list has 6 nodes. Each node has 2 links, one to it's next node, and one to it's 3rd node after itself. So, 1 points to 2 (shortlink) and 4(longlink), 2 points to 3 (shortlink) and 5 (longlink), and 3 points to 4 (shortlink) and 6 (longlink).

Anyway i got an integer value "number" which is holding the correct information in it. I need to be able to make node 6 have a long link to itself when node 3 is deleted (as node 3 points to 6). The problem i'm having is that when i delete node 3, node 6 is still pointing to node 3 and not itself. The "num" you see there is the value of the longlink number each node has. Any ideas to see what i'm doing wrong?
I know "number" is holding the correct value in there (which is 6 when 3 gets deleted), as i've tested it just before the for loop with a cout statement. Once it gets into the for loop, it cannot access "number" variable. Any ideas?
Basically, all i'm trying to do is go through each node in the list, and if that node's longlink number equal to the number variable, then update the number.

Last edited by coolio2006; 26Aug2006 at 19:37..
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
Quote:
Originally Posted by coolio2006
I have a slight issue yet again. The code is:

Code:
for (int z = 1; z <= length; z++)
{
if (longlinker -> longlink -> num == number)
{
longlinker -> longlink -> num = number;
}
else
{
longlinker = longlinker -> shortlink;
}
Now, assume the linked list has 6 nodes. Each node has 2 links, one to it's next node, and one to it's 3rd node after itself. So, 1 points to 2 (shortlink) and 4(longlink), 2 points to 3 (shortlink) and 5 (longlink), and 3 points to 4 (shortlink) and 6 (longlink).

Anyway i got an integer value "number" which is holding the correct information in it. I need to be able to make node 6 have a long link to itself when node 3 is deleted (as node 3 points to 6). The problem i'm having is that when i delete node 3, node 6 is still pointing to node 3 and not itself. The "num" you see there is the value of the longlink number each node has. Any ideas to see what i'm doing wrong?
I know "number" is holding the correct value in there (which is 6 when 3 gets deleted), as i've tested it just before the for loop with a cout statement. Once it gets into the for loop, it cannot access "number" variable. Any ideas?
Basically, all i'm trying to do is go through each node in the list, and if that node's longlink number equal to the number variable, then update the number.

I've tried other pieces of code and changing it slightly, but the number variable refuses to go into my do/while loops, or my while or for loops. Why is that? "number" is declared in the function itself.

The other code i came up with which is not working is:

Code:
do
{
cout << "your mom " << number << endl;
if (longlinker -> num == number)
longlinker -> longlink -> num = number;
longlinker = longlinker -> shortlink;
}
while (longlinker -> shortlink -> num != start -> num);
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
Can anyone help me out please?
coderzone's Avatar, Join Date: Jul 2004
Team Leader
I guess you are making the simple thing a bit more complex. If you ara using shortlink as well as long link deleting a node becomes a large process.

As you mentioned in the example
"3 points to 4 (shortlink) and 6 (longlink)"

So now when deleting a node you need to keep in mind the following.

1. Mark the node for deletion. Lets say its node 4
2. Update the links that can point to the node we are deleting. In your case the short link as well as the long link. As we are deleting node 4 you need to first update node 3 for its short link and node 1 for its long link
3. Now safely remove the node.

Also if the if condition is not satisfied then it will not execute the if block. That means your number is never equal to longlinker -> longlink -> num
coolio2006's Avatar, Join Date: Aug 2006
Go4Expert Member
Thanks for your feedback coderzone. Just let me know if this approach is right (well i'm assuming it's not as it's not working). Assuming the linked list has 8 nodes and 3 k (k being the longlink).
I find the node for deletion (lets say node 4). I make node 3 point to node 5 (that works well). Then what i'm doing is, i'm saving the actual longlink of node 4 (into the variable int number - which should store 7 - and it does with the testing i've done). Once i've saved my node number, i iterate through the list to see which nodes longlink is pointing to 4, and i update the longlink of that node to the value of 7. So technically, the node i've found through iteration that was long linking to 1 should now actual have the value 7.
Now, i notice that the number variable is storing what i want it to store, but when i try and use that number variable in my for (or my do while loop) - it just cannot access it - i.e. the if statement doesn't recognise the data in number?
Isn't that correct?
coderzone's Avatar, Join Date: Jul 2004
Team Leader
You dont need to iterate to find the long link. You always know. Its just 2 nodes behind. Unless its first or second node.