私信TA

用户名:3377940682

访问量:785

签 名:

等  级
排  名 1203
经  验 2983
参赛次数 4
文章发表 5
年  龄 0
在职情况 学生
学  校 泰州学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;

typedef struct LNode{
    ElemType data;
    struct LNode *next;
}*LinkList,LNode;

void CreatList(LinkList &L,int n){
    L=(LinkList)malloc(sizeof(LNode));
    LNode *s,*r=L;
    int x;
    for (int i=0;i<n;i++){
        s=(LNode *)malloc(sizeof(LNode));
        scanf("%d",&x);
        s->data=x;
        r->next=s;
        r=s;
    }
    r->next=NULL;
}

void DeleteList(LinkList &L,ElemType x){
    LNode *pre=L;
    LNode *p=L->next;
    LNode *q;
    while (p!=NULL){
        if (p->data==x){
            q=p;
            pre->next=p->next;
            p=p->next;
            free(q);
        }else{
            pre=p;
            p=p->next;
        }
    }
}

void Print(LinkList L){
    LNode *p=L->next;
    while (p!=NULL){
        printf("%d ",p->data);
        p=p->next;
    }
}
int main(){
    LinkList L;
    int n,x;
    scanf("%d",&n);
    CreatList(L,n);
    scanf("%d",&x);
    DeleteList(L,x);
    Print(L);
    return 0;
}

 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区