title: C++: Linked List Representation
body: <p>The way <b>I</b> know how to represent a linked list is basically creating a <b>Node</b> class (more preferably a <b>struct</b>), and the creating the actual <b>linkedList</b> class. However, yesterday I was searching for the logic of <b>reversing a singly linked list</b> operation and almost 90% of the solutions I've encountered was including that the function, returning data type <b>Node* </b>. Thus I got confused since if you want to reverse a list no matter what operation you done, wouldn't it be in the type of <b>linkedList</b> again? Am I doing it the wrong way?</p>
  
  <p>The linked list implementation <b>I</b> do all the time;</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct Node
  {
      int data;
      Node *next;
  };
  
  class linkedList
  {
  public:
      Node* firstPtr;
      Node* lastPtr;
  
      linkedList()
      {
          firstPtr=lastPtr=NULL;
      }
      void insert(int value)
      {
          Node* newNode=new Node;
          newNode-&gt;data=value;
          if(firstPtr==NULL)
              firstPtr=lastPtr=newNode;
          else {
              newNode-&gt;next=firstPtr;
              firstPtr=newNode;
          }
      }
      void print()
      {
          Node *temp=firstPtr;
          while(temp!=NULL)
          {
              cout&lt;&lt;temp-&gt;data&lt;&lt;" ";
              temp=temp-&gt;next;
          }
      }
  };
  </code></pre>