title: Adding 2 Polynomial Expressions Using Linked List C++
body: <p>Below is my source code which is to generate 2 polynomials which are given by the user input. Now, I'm stuck on how to add both polynomials and display the result. I have the idea how to evaluate which is we check the exponent in the list. If same, the coefficient will add. If not, the current node will proceed to the next node and compare to the other node.Is that right? Actually I'm quite confused about linked list.</p>
  
  <pre><code> #include&lt;iostream&gt;
  using namespace std;
  class Node{
        public :
               int coef;
               int exp;
               Node *next;
        private:
        };
  
  class List{
        public:
               List(){
                      head = NULL;
               }
               void insert(int x, int y){ //inserting node
                    Node *newNode = new Node;
                    newNode-&gt;coef = x;
                    newNode-&gt;exp = y;
                    newNode-&gt;next = NULL;
  
                    if(head==NULL){
                                   head = newNode;
                    }
                    else{
                         Node *currNode = head;
                         while(currNode-&gt;next!=0){
                               currNode = currNode-&gt;next;
                         }
                         currNode-&gt;next = newNode;
                    }
               }
               void display(){ //display the expression
                    Node *currNode = head;
                    cout&lt;&lt;"\n\n\t";
                    while(currNode-&gt;next!=0){
                          //cout&lt;&lt;"Coef: "&lt;&lt;currNode-&gt;coef&lt;&lt;"\t"&lt;&lt;"Expo: "&lt;&lt;currNode-&gt;exp&lt;&lt;endl;
                          cout&lt;&lt;currNode-&gt;coef&lt;&lt;"X^"&lt;&lt;currNode-&gt;exp&lt;&lt; "+";
                          currNode = currNode-&gt;next;
                    }
                    cout&lt;&lt;currNode-&gt;coef&lt;&lt;"X^"&lt;&lt;currNode-&gt;exp&lt;&lt;endl;
                    //cout&lt;&lt;"Coef: "&lt;&lt;currNode-&gt;coef&lt;&lt;"\t"&lt;&lt;"Expo: "&lt;&lt;currNode-&gt;exp&lt;&lt;endl;
               }
        private:
                Node *head;              
        };
  
  int main(){
  
      List seq1,seq2;
  
      int x,y,a,b;
      cout&lt;&lt;"Enter your expression 1: "&lt;&lt;endl;
  
      while(cin&gt;&gt;x&gt;&gt;y,x!=0&amp;&amp;y!=-1){
              seq1.insert(x,y);
      }
      seq1.display();
      cout&lt;&lt;endl;
      cout&lt;&lt;"Enter your expression 2: "&lt;&lt;endl;
  
      while(cin&gt;&gt;a&gt;&gt;b,a!=0&amp;&amp;b!=-1){
              seq2.insert(a,b);
      }
      seq2.display();
  
      return 0;
  }
  </code></pre>