title: How to get below linked list with friend operator to working?
body: <p>I am trying to execute linked list with the below code.But I am unable to figure out the mistake in it.
  I got the concept of it but I am failing to implement the same.
  Any help is highly appreciated.</p>
  
  <pre><code>#include &lt;iostream&gt;
   using namespace std;
  
   struct Node {
   int data;
   Node *next;
   Node(int j) : data(j), next(nullptr) {}
   friend ostream &amp;operator&lt;&lt;(ostream &amp;os, const Node &amp;n) {
   cout &lt;&lt; "Node\n"
       &lt;&lt; "\tdata: " &lt;&lt; n.data &lt;&lt; "\n";
      return os;
    }
   };
  void addElement(Node **head, int data){
  Node *temp = nullptr;
  temp-&gt;data = data;
  temp-&gt;next=nullptr;
  Node *cur = *head;
  while(cur) {
      if(cur-&gt;next == nullptr) {
          cur-&gt;next = temp;
          return;
      }
      cur = cur-&gt;next;
  }
   };
   void printList(const Node *head){
   const Node *list = head;
  while(list) {
      cout &lt;&lt; list;
      list = list-&gt;next;
  }
  cout &lt;&lt; endl;
  cout &lt;&lt; endl;
    };
   void deleteList(Node *head){
  Node *delNode =nullptr;
  while(head) {
      delNode = head;
      head = delNode-&gt;next;
      delete delNode;
  }};
  
    int main() {
    Node *list = nullptr;
    addElement(&amp;list, 1);
    addElement(&amp;list, 2);
    printList(list);
     deleteList(list);
     return 0;
     }
  </code></pre>
  
  <p>after compiling I am getting no error and no output.So I am unable to figure what is going wrong or else my implementation of which is not right!</p>