回覆列表
  • 1 # 何以笙丶丶

    #include

    #include

    #define LEN sizeof(struct Node)

    struct Node

    {

    int num ;

    struct Node *next;

    };

    int main()

    {

    struct Node *creat();

    struct Node *del(struct Node *head);

    void print(struct Node *);

    struct Node *head;

    head=creat();

    print(head);

    del(head);

    print(head);

    return 0;

    }

    //建立連結串列的的函式

    struct Node *creat()

    {

    struct Node *head;

    struct Node *p1,*p2;

    p1=p2=(struct Node *) malloc(LEN);

    head=NULL;

    int n = 0;

    p1->num = n;

    while (p1->num

    {

    n=n+1;

    if(n==1)head=p1;

    else p2->next=p1;

    p2=p1;

    p1=(struct Node *)malloc(LEN);

    p1->num = n;

    }

    p2->next=NULL;

    return (head);

    }

    struct Node *del(struct Node *head)

    {

    struct Node *p,*q,*f,*r;

    p=head;

    while(p!=NULL)

    {

    r=p;

    f=r->next;

    while(f!=NULL)

    {

    if(f->num % 2 != 0)

    {

    q=f;

    r->next=f->next;

    f=f->next;

    free(q);

    }

    else

    {

    r=f;

    f=f->next;

    }

    }

    p=p->next;

    }

    return head;

    }

    //輸出連結串列的函式

    void print(struct Node *head)

    {

    struct Node *p;

    p=head;

    while (p!=NULL)

    {

    printf("%d\n",p->num);

    p=p->next;

    }

    }

  • 中秋節和大豐收的關聯?
  • 詹姆斯拒絕總價值1.15億美金的合同,背後蘊藏著怎樣的故事?