title: how to check if linked list is empty
body: <p>I am making a project and I need to add products into linked list. when I add products it also count the initialized value as a product. in my code I add the products "aaaa" with price 20 and "bbbb" with price 111, when I print the products prices its print: "0 20 111". the value "0" is the initialized value, and I don't the program to save it. I need to find out if the list is empty and if so to add the first item to the list. How do I do it? <br><br>This is my code:</p>
  
  <p><strong>main.cpp:</strong></p>
  
  <pre><code>#include &lt;iostream&gt; 
  //#include &lt;string&gt;
  using namespace std;
  #include "List.h"
  int main(){
      int option;
      Product productsListHead;
      productsListHead.printProducts(&amp;productsListHead);
      productsListHead.addProduct(&amp;productsListHead,1,"aaaa",20);
      productsListHead.printProducts(&amp;productsListHead);
      productsListHead.addProduct(&amp;productsListHead,2,"bbbb",111);
      if(option==1){
          productsListHead.printProducts(&amp;productsListHead);
      }
      return 1;
  }
  </code></pre>
  
  <p><strong>List.cpp:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  #include "List.h"
  using namespace std;
  
      void Product::addProduct(Product* head,int id,char* name, int price){
          Product* TheNewProduct = new Product;
          TheNewProduct-&gt;setNext(NULL);
          TheNewProduct-&gt;setId(id);
          TheNewProduct-&gt;setName(name);
          TheNewProduct-&gt;setPrice(price);
          Product *tmp = head;
  
          if ( tmp != NULL ) 
          {
              cout&lt;&lt;"the list is not empty"&lt;&lt;endl;
          // Nodes already present in the list
          // Parse to end of list
              while ( tmp-&gt;Next() != NULL ) {
                  tmp = tmp-&gt;Next();
              }
  
              // Point the last node to the new node
              tmp-&gt;setNext(TheNewProduct);
          }
          else
          {
              cout&lt;&lt;"the list is empty"&lt;&lt;endl;
              // First node in the list
              head = TheNewProduct;
          }
      }
      void Product::printProducts(Product* head)
      {
          //Product* tmp=head;
          for ( ; head; head = head-&gt;Next() )
        {
            cout &lt;&lt; head-&gt;Price() &lt;&lt; endl;
        }
      }
      Product::Product(){
          next=NULL;
          id=0;
          name="";
          price=0;
      }
  </code></pre>
  
  <p>header files->List.h:</p>
  
  <pre><code>#pragma once
  #ifndef LIST_H
  #define LIST_H
  
  //#include &lt;string&gt;
  using namespace std;
  
  class Product{
      private:
          int id;
          char* name;
          int price;
          Product* next;
      public:
          Product();//constructor
          //Product* Next(){return next;};
          //~Products();
          Product* Next() { return next; };
          int Id(){return id;};
          char* Name(){return name;};
          int Price(){return price;};
  
          void setId(int new_id){id=new_id;};
          void setPrice(int new_price){price=new_price;};
          void setNext(Product* new_next){next=new_next;};
          void setName(char* new_name){name=new_name;};
          void printProducts(Product* head);
          void addProduct(Product* head,int id, char* name, int price);
          //void updateNameProduct(int id, char* oldName, char* newName); 
      };
  #endif
  </code></pre>