title: Command terminated by signal 11
body: <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;malloc.h&gt;
  struct node{
    char data;
    int p;
    struct node *ptr;
  };
  struct node *start=NULL;
  struct node *insert()
  {
    struct node *new_node,*z;
    int num;
    char s;
    printf("\nEnter -1 to stop.");
    printf("\nEnter the characters and their priorities: ");
    scanf("\n%c %d",&amp;s,&amp;num);
    while(num!=-1)
    {
      new_node=(struct node *)malloc(sizeof(struct node));
      new_node-&gt;data=s;
      new_node-&gt;p=num;
      if(start==NULL)
      {
        start=new_node;
        z=start;
        new_node-&gt;ptr=NULL;
      }
      else
      {
        z-&gt;ptr=new_node;
        new_node-&gt;ptr=NULL;
        z=z-&gt;ptr;
      }
      scanf("%c %d",&amp;s,&amp;num);
    }
    return start;
  }
  struct node *display()
  {
    struct node *z;
    z=start;
    printf("\nDisplaying elements:\n");
    while(z!=NULL)
    {
      printf("\t%c [Priority=%d]\n",z-&gt;data,z-&gt;p);
      z=z-&gt;ptr;
    }
    return start;
  }
  struct node *sortit()
  {
    struct node *z,*q;
    int t;
    char x;
    z=start;
    while(z-&gt;ptr!=NULL)
    {
      q=z-&gt;ptr;
      while(q!=NULL)
      {
        if(z-&gt;p&gt;q-&gt;p)
        {
          t=z-&gt;p;
          x=z-&gt;data;
          z-&gt;p=q-&gt;p;
          z-&gt;data=q-&gt;data;
          q-&gt;p=t;
          q-&gt;data=x;
        }
        q=q-&gt;ptr;
      }
      z=z-&gt;ptr;
    }
    return start;
  }
  struct node *new_insert()
  {
    struct node *y,*z;
    int n;
    char s;
    y=(struct node *)malloc(sizeof(struct node));
    printf("\nEnter character and priority for new node:");
    scanf("%c %d",&amp;s,&amp;n);
    printf("%c",s);
    y-&gt;data=s;
    y-&gt;p=n;
    printf("%c",y-&gt;data);
    printf("%d",y-&gt;p);
    if(n&lt;start-&gt;p)
    {
      y-&gt;ptr=start;
      start=y;
      printf("%d",y-&gt;p);
    }
    else
    {printf("\nff");
      z=start;
    while(z-&gt;ptr-&gt;p&lt;=n&amp;&amp;z-&gt;ptr!=NULL)
      z=z-&gt;ptr;
    y-&gt;ptr=z-&gt;ptr;
    z-&gt;ptr=y;
  }
    return start;
  }
  int main()
  {
    insert();
    display();
    sortit();
    display();
    new_insert();
    display();
    return 0;
  }
  </code></pre>
  
  <p>In this C code, I have tried to implement priority queues.</p>
  
  <p>Everything works perfectly fine except the <code>new_insert()</code> function. The print statements after <code>y-&gt;p=n;</code> in <code>new_insert()</code> function print <code>0</code>.</p>
  
  <p>Hence, the function doesn't work properly. Also, in <code>display()</code> function the print statement prints the <code>[Priority]</code> twice.</p>
  
  <p>Hence, I am not able to add an external node in my priority queue.</p>