链表插入数据,小于等于0的部分插入不了是怎么回事??

链表有序插入数据,小于等于0的部分插入不了是怎么回事?????各位大神求解。。。。

那得看你代码咋写的啊

什么意思?你要把问题描述清楚

  • #include<stdio.h>
    #include<stdlib.h>
    typedef struct node{
    int data;
    struct node next;
    }linklist;
    int search(linklist
    head,int n){
    linklist* tail;
    tail=head;
    int count=0;
    while(tail!=NULL){
       if(tail->data==n){
           count=1;
       }
       tail=tail->next;
    
    }
    return count;
    }
    linklist createList(linklist head){
    int m,i;
    linklist *p;
    head->next = NULL;
    p = head;
    scanf("%d",&m);
    if(m==0){
      head=NULL;
      return head;
    
    }
    for (i = 0; i < m; i++)
    {
      linklist* s = (linklist*)malloc(sizeof(linklist));
      scanf("%d", &s->data);
      p->next = s;
      s->next = NULL;
      p = s;
    
    }
    return head;
    }
    linklist *insertList(int X,linklist *L){
    /*linklist *p,*q,*s;
    s=(linklist *)malloc(sizeof(linklist));
    s->data=n;
    s->next=NULL;
    if (head==NULL) return p;
    p=q=head;
    while (q!=NULL && q->data < n){
      p=q;
      q=q->next;
    
    }
    if (p->datadata){
      s->next=p;
      head=s;
    
    }
    else{
      s->next=q;
      p->next=s;
    
    }
    return head;/
    linklist
    head=L;
    L=L->next;
    linklist* node=(linklist )malloc(sizeof(linklist));
    node->data=X;
    node->next=NULL;
    linklist
    q=head;
    if(L==NULL)
    {
      head->next=node;
      return head;
    
    }
    while(L->data<X)
    {
      q=L;
      L=L->next;
      if(L->next==NULL)
      {
          L->next=node;
          return head;
      }
    
    }
    node->next=L;
    q->next=node;
    return head;
    }
    int main()
    {
    linklist* head = (linklist*)malloc(sizeof(linklist));
    int n;
    head=createList(head);
    scanf("%d",&n);
    if(search(head,n)==1){
      linklist *t;
      t=head->next;
      int s1=0;
      while (t!=NULL){
         if(s1>=1)printf(" ");
          s1++;
         printf("%d",t->data);
         t=t->next;
      }
      printf("\n");
    
    }
    else {
      if (head==NULL)
        printf("%d",n);
      if(n<=0){
          printf("%d ",n);
          linklist *t;
          t=head->next;
          int s1=0;
          while (t!=NULL){
          if(s1>=1)printf(" ");
          s1++;
         printf("%d",t->data);
         t=t->next;
         }
      }
      if(n>0) { 
      head=insertList(n,head);
      linklist *t;
      t=head->next;
      int s1=0;
      while (t!=NULL){
          if(s1>=1)printf(" ");
          s1++;
         printf("%d",t->data);
         t=t->next;
      }
    
    }
    }
    return 0;
    }