title: problem implementing simple linked list in c++, no output
body: <p>For my C++ programming course, my task is to implement a simple linked list using my own functions of <code>addElement()</code>, <code>printList()</code> and <code>deleteList()</code>. </p>
  
  <p>When I compile and run the following program, nothing happens. I get no warnings and using valgrind I couldn't find anything wrong.</p>
  
  <p>The program code I am working with is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct Node {
    int data;
    Node *next;
    Node(int i) : data(i), next(nullptr) {}
    friend ostream &amp;operator&lt;&lt;(ostream &amp;os, const Node &amp;n) {
      os &lt;&lt; "Node\n"
         &lt;&lt; "\tdata: " &lt;&lt; n.data &lt;&lt; "\n\tthis: " &lt;&lt; &amp;n &lt;&lt; "\n\tnext: " &lt;&lt; n.next;
      return os;
    }
  };
  
  void addElement(Node **head, int data);
  void printList(Node *head);
  void deleteList(Node *head);
  
  void deleteList(Node *head) {
    Node *next = head;
    while (next) {
      Node *deleteMe = next;
      next = next-&gt;next;
      delete deleteMe;
    }
  }
  
  void addElement(Node **head, int data) {
    Node *n = new Node(data);
    n-&gt;next = *head;
    head = &amp;n;
  }
  
  void printList(Node *head) {
    Node *next = head;
    while(next) {
      cout &lt;&lt; next-&gt;data;
      next = next-&gt;next;
    }
  }
  
  int main() {
    Node *list = nullptr;
    addElement(&amp;list, 1);
    addElement(&amp;list, 2);
    addElement(&amp;list, 3);
    addElement(&amp;list, 4);
    printList(list);
    deleteList(list);
    return 0;
  }
  </code></pre>
  
  <p>I have no idea why my code does not work and produce output.
  Please help and kind regards</p>