链表的删除

链表的删除,第1张

链表的删除

#include
#include

typedef struct node
{
    int data;
    struct node* next;
}*PNODE, NODE;

PNODE header;
//PNODE ender;

PNODE create()
{
    PNODE header = (PNODE)malloc(sizeof(node));
    header->next = NULL;
    PNODE q = header;
    int n;
    scanf_s("%d", &n);
    while (n--)
    {
        int a;
        scanf_s("%d", &a);
        PNODE p = (PNODE)malloc(sizeof(node));
        p->data = a;
        //  p->next = header->next;
        p->next = NULL;
        q->next = p;
        q = p;
    }
    return header;
}


void delete1(PNODE header)
{
    while (header->next)
    {
        if (header->next->data % 2 == 0)
            header->next = header->next->next;
        else
            header = header->next;
    }
}

void show(PNODE header)
{
    header = header->next;

    while (header)
    {
        if (header->next == NULL)
        {
            printf("%d ", header->data);
            break;
        }
        else
        {
            printf("%d ", header->data);
            header = header->next;
        }


    }
}

int main() {

    PNODE p = create();
    delete1(p);
    show(p);
    printf("n");
   

    return 0;

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5593873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存