title: reverse a string using singly linked list
body: <p>i am trying to print the reverse of the string using linked list. suppose my string is "World is full of good people" , it should print "people good of full is World"</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  /******** Fucntions Prototype *********/
  
  void printList();
  
  
  typedef struct Node
  {
      string data;
      struct Node *next;
  }node;
  
  struct Node* newNode(string userData)
  {
      node *temp = new Node;
      temp-&gt;data = userData;
      temp-&gt;next = NULL;
      return temp;
  }
  
  void printList(node* head)
  {
      node *temp = head;
      while(temp != NULL)
      {
          cout&lt;&lt;temp-&gt;data&lt;&lt;" ";
          temp = temp-&gt;next;
      }
  }
  void reverseList(node *head)
  {
      node *curr = head;
      node *prev = NULL, *next = NULL;
      while(curr != NULL)
      {
          next = curr-&gt;next;
          curr-&gt;next = prev;
          prev = curr;
          curr = next;
      }
      head = prev;
  
  }
  int main()
  {
      node *head = newNode("World");
      head-&gt;next = newNode("is");
      head-&gt;next-&gt;next = newNode("full");
      head-&gt;next-&gt;next-&gt;next = newNode("of");
      head-&gt;next-&gt;next-&gt;next-&gt;next = newNode("good");
      head-&gt;next-&gt;next-&gt;next-&gt;next-&gt;next = newNode("people");
      cout&lt;&lt;"Linked list before reverse is:\n";
      printList(head);
      cout&lt;&lt;"\n";
      reverseList(head);
      cout&lt;&lt;"Linked list after reverse is:\n";
      printList(head);
  
      return 0;
  }
  </code></pre>
  
  <p>So if the string is "World is full of good people", the expected output is 
  "people good of full is world", hence reversing the node. But is getting "World" as output</p>