title: ProblemChecking If A Linked List Is Palindrome Or Not
body: <p>I am trying the check if a link is palindrome or not using the following method:</p>
  
  <p>1) Create and read the original linked list from user.
  2) Traverse through the original linked list and using the stack implementation using linked list reverse the original linked list.
  3) Initialize flag = 1. Traverse through both the linked lists and compare each node and break the loop and print "Not Palindrome" if any two node data doesn't match else print "Palindrome".</p>
  
  <p>The Program Is Given Below: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int flag = 1;
  
  struct node {
      int data;
      struct node *next;
  }*start = NULL, *head = NULL;
  
  void create() {
      char ch;
  
      do {
          struct node *new_node, *prev;
          new_node = (struct node*)malloc(sizeof(struct node));
          printf("Please Enter The Data: ");
          scanf("%d", &amp;new_node-&gt;data);
          new_node-&gt;next = NULL;
          if(start == NULL) {
              start = new_node;
          } else {
              prev-&gt;next = new_node;
          }
          prev = new_node;
          printf("Do You Still Want To Insert(y/n)? ");
          fflush(stdin);
          scanf("%c", &amp;ch);
      }while(ch != 'n');
  }
  
  void reverse() {
      struct node *current;
      current = start;
      while(current != NULL) {
          struct node *new_node, *prev;
          new_node = (struct node*)malloc(sizeof(struct node));
          new_node-&gt;data = current-&gt;data;
          new_node-&gt;next = NULL;
          if(head == NULL) {
              head = new_node;
          } else {
              new_node-&gt;next = head;
              head = new_node;
          }
          prev = new_node;
          current = current-&gt;next;
      }
  
  }
  
  int checkPal() {
      struct node *current1, *current2;
      current1 = start;
      current2 = head;
      while(current1 != NULL &amp;&amp; current2 != NULL) {
          if(current1-&gt;data != current2-&gt;data) {
              flag = 0;
              break;
          }
          current1 = current1-&gt;next;
          current2 = current2-&gt;next;
      } 
      if(flag = 1)
          return 1;
      else
          return 0;
  }
  
  void display(struct node *list) {
      while(list != NULL) {
          printf("%d --&gt; ", list-&gt;data);
          list = list-&gt;next;
      }
      printf("NULL\n");
  }
  
  int main() {
      create();
      printf("The original linked list is: \n");
      display(start);
      reverse();
      printf("The reversed linked list is: \n");
      display(head);
      if(checkPal()) {
          printf("The Linked List Is Palindrome!\n");
      } else {
          printf("The Linked List Is Not Palindrome!\n");
      }
  }
  </code></pre>
  
  <p>However, I am always getting "The Linked List Is Palindrome!" even when it is not! What did I do wrong? </p>
  
  <p><strong>NOTE:</strong> To be done only with singly linked list.</p>