赵相宇的第三次博客作业

奇数值结点链表

struct ListNode *readlist()

{

  struct ListNode *head=NULL,*p=NULL,*tail=NULL,*ptr=NULL;

  int data;

  scanf("%d",&data);

  while(data!=-1)

  {

    p=(struct ListNode *)malloc(sizeof(struct ListNode));

    p->data=data;

    p->next=NULL;

    if(head==NULL)

    {

      head=p;

    }else

    {

      tail->next=p;

    }

    tail=p;

    scanf("%d",&data);

  }

  return head;

}

struct ListNode *getodd( struct ListNode **L )

   struct ListNode *p=*L,*r,*s,*head1,*head2;

    head1=(struct ListNode*)malloc(sizeof(struct ListNode));

    head2=(struct ListNode*)malloc(sizeof(struct ListNode));

    head1->next=NULL;

    head2->next=NULL;

    r=head1;

    s=head2;

    while(p)

    {

        if(p->data%2!=0)

        {

            r->next=p;

            r=p;

        }

        else

        {

            s->next=p;

            s=p;

        }

        p=p->next;

    }

    r->next=NULL;

    s->next=NULL;

    *L=head2->next;

    return head1->next;

这个是借鉴袁中的第一次pta。其他的还没弄会

posted @ 2018-04-23 06:31  赵相宇  阅读(153)  评论(1编辑  收藏  举报