Node* L1 = NULL, *L2 = NULL;
Node* one = new Node(9);
Node* two = new Node(9);
L1=one;
one->next=two;
Node* four = new Node(0);
Node* five = new Node(9);
Node* six = new Node(9);
L2=four;
four->next=five;
five->next=six;
cout<<CheckSmaller(L1, L2)<<endl;
Eyad wrote:
i ma not performing anything!!!
So, you're saying the above code is part of your linked list class? That doesn't make sense, and neither does your imitation of Mario.
yes, should i post the whole code? i only posted the function implementation. and its job is clear which is returning one of three values ( 1, -1 or 0)
What happens when if(!num1 && !num2) return 0; //num1 == NULL and num2 is pointing to something?
Without knowing things like what Length() returns in this case, it's not clear what return value would be the result of that function. And you haven't given us what the wrong output is.
WHy would you put test code in a member function of your linked list class? Can't you test it out more easily from outside the class by using your convenient methods to add values to the list?
I didn't say that, I'm just asking, for your test case. Is 99 equal to 099 or is 99 less than 099. What is the expected output? (trying to help you here).
Let me clarify:
In your example L1 = 99, L2 = 099.
First pass.
1 2 3 4 5 6 7 8 9 10 11
if(!num1 && !num2) return 0; // evaluate false
if(Length(num1) > Length(num2))// No false
if(Length(num1) < Length(num2)) //Yes true
if(num1->value <= num2->value) //No false
elsereturn CheckSmaller(num1->next, num2->next); //num1->next val 9, num2->next val 9
//recursive call...
if(!num1 && !num2) return 0; // evaluate false
if(Length(num1) > Length(num2))// No false
if(Length(num1) < Length(num2)) //Yes true
if(num1->value <= num2->value) //true return 1 so you deem 99 < 099
By your logic then, if L1 were say = 10, and L2 were say = 001, L1 is less than L2
You should make the rest of your linked list class work before you tackle this. If you cannot even call a method to add to a linked list for you, you have a long way to go before you can bake that cake.