title: I wrote this program to reverse the elements in a linked list, after compiling this program this is showing error in the reverse (). why?
body: <p>I wrote this program to reverse the elements in a linked list, after compiling this program this is showing error in the reverse (). why?</p>
  
  <p>error showing :- 
  ||In function ‘void reverse()’:|
  |40|error: no match for ‘operator=’ (operand types are ‘Node’ and ‘long int’)|
  |40|note: candidate is:|</p>
  
  <pre><code>    #include&lt;iostream&gt;
  using namespace std;
  struct Node
  {
      int data;
      Node* next;
  };
  Node* head;
  void insert(int data)
  {
     Node* newNode = new Node();    // create a new node
     newNode-&gt;data = data;
     newNode-&gt;next = NULL;
  
     if(head == NULL ){   //if head is null, that means this is your first node
        head = newNode;   //so update the value of head
     }else{
        Node* temp = head;
       while(temp-&gt;next!=NULL)
       {
          temp = temp-&gt;next;
       }
       temp-&gt;next = newNode;
     }
   }
  void print()
  {
      Node* temp = head;
      while(temp!=NULL)
      {
          cout&lt;&lt;" "&lt;&lt;temp-&gt;data&lt;&lt;" ";
          temp = temp-&gt;next;
      }
      cout&lt;&lt;endl;
  }
  void reverse()
  {
      Node* current;
      Node* prev;
      Node* nextaddress;
      current = head;
      prev = NULL;
      while(current!=NULL)
      {
          nextaddress = current-&gt;next;
          current-&gt;next = prev;
          prev = current;
          current = nextaddress;
      }
      head = prev;
  }
  int main()
  {
      head = NULL;
      int a, n;
      cout&lt;&lt;"\n enter the number of elements to be stored into the list :";
      cin&gt;&gt;n;
      cout&lt;&lt;"\n enter those elements :";
      for(int i=1; i&lt;=n; i++)
      {
          cin&gt;&gt;a;
          insert(a);
      }
      print();
      cout&lt;&lt;"\n the reverse of the linkedlist is :";
      reverse();
      print();
      return 0;
  }
  </code></pre>