level 7
懂学的小鸟
楼主
求大神帮我看看,是我手机问题还是代码问题啊?
上代码
#include<stdio.h>
#include<stdlib.h>
struct zz{
int id;
struct zz* next;
};
int n=0;
struct zz*head1;
struct zz *c(void)//创建链表
{
struct zz *a,*b,*head;
a=b=(struct zz*)malloc(sizeof (struct zz));
scanf("%d",&a->id);
while (a->id!=0)
{
n+=1;
if (n==1)
head=a;
else
b->next=a;
b=a;
a=(struct zz*) malloc (sizeof (struct zz));
scanf("%d",&a->id);
}
b->next=NULL;
head1->next=head;
return (head1);
}
void xs()//打印链表
{
struct zz*p=head1;
p=p->next;
while (p!=NULL)
{
printf ("%d\n",p->id);
p=p->next;
}
}
void sc()//删除链表
{
struct zz *q,*p,*temp;
int i=0;
q=p=head1;
p=p->next;
scanf("%d",&i);
while (p!=NULL)
{
if (p->id==i)
{
q->next=p->next;
temp=p;
p=p->next;
free(temp);
temp=NULL;
}else{
q=q->next;
p=p->next;
}
}
}
int main()
{
struct zz*z;
z=c();//创建
xs();//显示
sc();//删除
xs();//显示
free(z);
}

2019年05月18日 01点05分
1
上代码
#include<stdio.h>
#include<stdlib.h>
struct zz{
int id;
struct zz* next;
};
int n=0;
struct zz*head1;
struct zz *c(void)//创建链表
{
struct zz *a,*b,*head;
a=b=(struct zz*)malloc(sizeof (struct zz));
scanf("%d",&a->id);
while (a->id!=0)
{
n+=1;
if (n==1)
head=a;
else
b->next=a;
b=a;
a=(struct zz*) malloc (sizeof (struct zz));
scanf("%d",&a->id);
}
b->next=NULL;
head1->next=head;
return (head1);
}
void xs()//打印链表
{
struct zz*p=head1;
p=p->next;
while (p!=NULL)
{
printf ("%d\n",p->id);
p=p->next;
}
}
void sc()//删除链表
{
struct zz *q,*p,*temp;
int i=0;
q=p=head1;
p=p->next;
scanf("%d",&i);
while (p!=NULL)
{
if (p->id==i)
{
q->next=p->next;
temp=p;
p=p->next;
free(temp);
temp=NULL;
}else{
q=q->next;
p=p->next;
}
}
}
int main()
{
struct zz*z;
z=c();//创建
xs();//显示
sc();//删除
xs();//显示
free(z);
}
