#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LinkList CreateList_n(int n)
{
LinkList L,p,q;
L=p=(LinkList)malloc(sizeof(LNode));
ElemType e;
int i;
for(i=1;i<=n;i++)
{
scanf("%d",&e);
q=(LinkList)malloc(sizeof(LNode));
q->data=e;
p->next=q;
p=q;
}
p->next=NULL;
return L;
}
void PrintList(LinkList L)
{
LNode *p=L->next;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
}
void DeleteListLessThanX(LinkList L,ElemType x) //就这边出了问题吧应该,不会改
{
LNode *p;
p=L->next;
scanf("%d",&x);
while(p!=NULL)
{
if(p->data<x)
{
p->next=p->next->next;
}
p=p->next;
}
}
int main()
{
int n,x;
LinkList L;
scanf("%d",&n);
L=CreateList_n(n);
getchar();
scanf("%d",&x);
DeleteListLessThanX(L,x);
PrintList(L);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void PrintList(LinkList L);
LinkList CreateList_n(int n)
{
int i=0;
LinkList L;
LNode *p,*q;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
p=L;
while(i<n)
{
q=(LinkList)malloc(sizeof(LNode));
scanf("%d",&q->data);
q->next=NULL;
p->next=q;
p=q;
i++;
}
return L;
}
void PrintList(LinkList L)
{
LNode *p;
p=L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
void DeleteListLessThanX(LinkList L,ElemType x) //就这边出了问题吧应该,不会改
{
LNode *p,*q;
p=L;
while(p!=NULL)
{
if(p->data<x)
{
q=p->next;
p->data=q->data;
p->next=q->next;
}
p=p->next;
}
}
int main()
{
int n,x;
LinkList L;
printf("n=");
scanf("%d",&n);
L=CreateList_n(n);
PrintList(L);
printf("x=");
scanf("%d",&x);
DeleteListLessThanX(L,x);
printf("数据展示");
PrintList(L);
return 0;
}
LinkList CreateList_n(int n)这个函数里面有问题