title: Trying to figure out linked list issues
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct ListNode
  {
      char data;
      ListNode *next;
  }*head = NULL, *nodeptr = NULL, *newNode = NULL;
  
  bool isPalindrome(ListNode*);
  
  int main()
  {
  
      char pali[] = "abaaba";//array of chars
  
      for (int i = 0; pali[i] != '\0'; i++)
      {
          newNode = new ListNode;
          newNode -&gt; data = pali[i]; //places chars into a linked list
          newNode -&gt; next = head;
          head = newNode;// links list together
          nodeptr = head;
  
  
          while(nodeptr != NULL)// prints out the chars
          {
              cout &lt;&lt; nodeptr -&gt; data;
              nodeptr = nodeptr -&gt;next;
          }
  
          cout &lt;&lt; endl;
  
          if(isPalindrome(head)) //prints if function true
              cout &lt;&lt; "Is a Palindrome" &lt;&lt; endl;
          else if(!isPalindrome(head)) //prints if function false
              cout &lt;&lt; "Not a Palindrome" &lt;&lt; endl;
  
  
      }
  
      return 0;
  }
  //test if the list is a palindrome
  bool isPalindrome(ListNode* headptr)
  {
      ListNode* topptr = headptr;//intializes to first char
      ListNode* botptr = headptr;//intializes to first char
      ListNode* temp = NULL;
  
      if(headptr != NULL &amp;&amp; headptr -&gt; next != NULL )//uses to initially test if the list is empty or a singleton
      {
  
          while(botptr-&gt;next != NULL)//places botptr at the last value pointing towards null
          {
              //cout &lt;&lt; botptr -&gt;data;
              botptr = botptr -&gt; next ;
          }
  
  
          while (topptr != temp ||  topptr -&gt; next != temp ) //reiterates until the list is the same as temp(empty) or if the next topptr(headptr) value is temp(singleton)
          {
              if(topptr -&gt; data != botptr -&gt; data)//stops if two values dont equal. I feel like the main problem is with this comparison.
              {
                  return false;
              }
  
              else if(botptr -&gt; data == topptr -&gt; data)//if two values do equal move topptr and botptr towards the middle by one.
              {
  
                  temp = topptr;
                  temp = topptr-&gt; next;
                  topptr = temp;//moves topptr down by one
                  temp = botptr;
                  botptr = topptr; //intializes botptr to the first in the next iteration
  
                  while(botptr -&gt; next != temp)
                  {
                      botptr = botptr -&gt; next;// move botptr up by one
                  }//places bottom pointer onto the last value pointer towards null or temp
              }
  
          }
      }
      return true; // returns true if only the list is empty or a singleton
  }
  </code></pre>
  
  <p>I'm having a hard time trying to figure out problems with this program. Every time I run it,it goes through the third iteration and just crashes. For some reason, I can't get the return false comparison working for the second iteration. It loops one time when it supposed to loop zero, since topptr equals b and botptr equals a. </p>