I don't know the details of what this function is trying to do, nor do I have the energy to try to figure it out, but something looks wrong with your set() function here:
void LList::set(int c, int val)
{
int i = size;
current = head;
if(i=(c+1))
I'm guessing you typed '=' when you meant '=='. And if you did mean '=', then why did you initialize 'i' to 'size' at the beginning of the function?
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
You sound far too urgent. What you need to realize is that 'urgent' for you does not mean 'urgent' for us. People aren't going to respond to your thread any faster than they normally would (and in fact they may reply slower or not at all).
Anyway, I'm a bit confused with your code. What exactly is add() supposed to do? Is it supposed to add a node to the linked list? Is it supposed to add data nodes together? Explain in more detail.
And what is this supposed to do?
ptrL = ptrL->next;
ptrL1 = ptrL1->next;
Before this, ptrL and ptrL1 pointed to the tails of their respective linked lists, did they not? Because if they did, they're now pointing to nothing, if you've set the next pointers at the end of the list to null (which is the normal way of implementing a linked list).
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
make the following changes to the set function.
void LList::set(int c, int val)
{
int i = size-1;
current = head;
while ( current != NULL )
{
if(i==c)
{
current->data = val;
//cout<<current->data;
break;
}
else
{
current = current->next;
i--;
}
}
}
You can easily debug these type of programs by using cout . Next time when you are programming, check function by function first before debugging the whole program at once. Also, you are using too many member variables.You are not using tail anywhere.
current and degree should not be member variables. They should be variables defined inside the functions. Having current and degree as member variables will give you some very hard to find bugs because they can be used and updated from any function and it is hard to keep track.
Figure out the way to stop printing the last + character. It can be easily done by having a check to find out if current->next is null or not.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115