title: seg fault in BFS traversal of BST
body: <p>I have implemented a binary tree and its BFS traversal. The program is below:  </p>
  
  <pre><code>struct elemq{
      int ele;
      struct elemq *left;
      struct elemq *right;
  };
  
  struct que{
      struct elemq *ss;
      struct que *next;
  }; 
  
  void qinsert(struct elemq *ptr){
      struct que *node;
      node = (struct que *)malloc(sizeof(struct que));
      if(front == NULL &amp;&amp; rear == NULL){
              node-&gt;ss = ptr;
              node-&gt;next = NULL;
              front = node;
              rear = node;
      }
      else{
              node-&gt;ss = ptr;
              node-&gt;next = NULL;
              rear-&gt;next = node;
              rear = node;
      }
  }
  
  struct elemq *qdelete(){
      if(front == NULL &amp;&amp; rear == NULL){
              cout &lt;&lt; "No elements to delete\n";
              exit(0);
      }
      struct elemq *dd = front-&gt;ss;
      struct que *ddd = front;
      front = front-&gt;next;
      free(ddd);
  return dd;
  }
  
  int isempty(){
      if(front == NULL &amp;&amp; rear == NULL){
              return 1;
      }
      else{
              return 0;
      }
  }
  
  void bfs(){
      qinsert(root);
      struct elemq *fff;
      while(!isempty()){
              fff = qdelete();
              cout &lt;&lt; fff-&gt;ele  &lt;&lt; "\n";
              if(fff-&gt;left != NULL){
                      qinsert(fff-&gt;left);
              }
              if(fff-&gt;right != NULL){
                      qinsert(fff-&gt;right);
              }
      }
  }  
  </code></pre>
  
  <p>Though the code is long, it is very simple to understand. elemq structure is the structure of a node in a tree. que is the queue i am using to implement bfs. q insert is to insert element into queue and qdelete deletes the element in the queue. isempty() is for checking if queue is empty or not. The program displays root element and then gives segmentation fault. Please help. struggling from quite some time.</p>