Addition of two polynomials using linked list ( compiled correctly but got runtime error)

there was a question in my book.
we have to add two polynomials using linked list.
the user inputs the terms of 1st polynomial and then inputs them in ascending order of power.
similarly enters 2nd polynomial.
i practiced on my codeblocks and got no compile error, but when i tried to run the program i got runtime error and output was not correctly displayed.
logic i used : i used function enqueue1 for poly1, enqueue2 for poly2 and enqueu3 for added polynomial.
i used start1,rear1 for poly 1 and similar for poly2 and added poly.
( i know i couldve made it more efficient but lets just focus on the problem now haha XD)
=>i compared linked lists by powers and just entered them into the added poly list(start3,rear3)
and displayed poly3;
can u guys pls help me find error in my code:-
my code: CodeChef: Practical coding for everyone
( :sweat_smile: my code was a bit lengthy so instead of posting the 100 lines here like that i just used this way, this code is for addition of polynomial using linked list and not that problem)
thakn you for help

What input did you give it?

1 Like

i gave the input:-
2
5 1 6 2
2
3 0 7 2

1 Like

Have you tried debugging it at all? Start with adding:

        cout << "addpoly - start1: " << start1 << " start2: " << start2 << endl;

under the lines:

    while(start1!=NULL && start2!=NULL)
    {

and it should hopefully be clear what’s going wrong :slight_smile:

1 Like