在上面我已经注释出来了,可能在算法上有错误,但这里主要先考虑的是语法上的错误!
题如下:
我在线等待哦!
#include<stdio.h>
#include<malloc.h>
#define NULL 0
typedef struct link{
float data;
struct link *next;
};
#define LEN sizeof(struct link)
int n;
struct link *creatlink(void)
{
struct link *head;
struct link *p1,*p2;
n=0;
p1=p2=(struct link*)malloc(LEN);
printf("input the data ,you can use data=10000 to end of action:");
scanf("%f",&p1->data);
head=NULL;
while(p1->data!=10000)
{
n++;
if(n==1)
head=p1;
else
p1=(struct link *)malloc(LEN);
p2->next=p1;
p2=p1;
printf("input the data:");
scanf("%f",&p1->data);
}
p2->next=NULL;
return(head);
}
void print(struct link *head )
{
struct link *p;
printf("Now ,These %d recods are:\n");
p=head;
if (head!=NULL)
do
{
printf("%f\n",p->data);
p=p->next;
}
while (p!=NULL);
}
struct link *insert(struct link *head,int i)
{
int j;
struct link *p0,*p1,*p2;
p1=head ;
p0=(struct link *)malloc(LEN);
printf("input the input data:");
scanf("%f",&p0->data);
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else if(i==1)
{
head=p0;
p0->next=p1;
}
else
if(i)
{
while(p1->next!=NULL&&j<i)
{
p2=p1;
p1=p1->next;
j++;
}
p2->next=p0;
p0->next=p1;
free(p2);
}
else
{
p1->next=p0;p0->next=NULL;
}
n=n+1;
return(head);
}
struct link * dellink(struct link *head,int i)
{
int j;
struct link *p1,*p2;
if(head==NULL)
{
printf("\n list null!\n");
return(head);
}
p1=head;
while(j<i&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
j++;
}
if(i==1)
head=p1->next;
else if(i)
{
p2->next=p1->next;
n--;
}
else printf("%ld not be found!\n",i);
return(head);
}
void main()
{
struct link *creatlink(void);
void print(struct link *head);
struct link *insert(struct link *head,int i);
struct link *dellink(struct link *head,int i);
struct link *head;
int i;
char a;
head = creatlink(void);//syntax error : missing ')' before 'type'
print(head);
printf("The link have been creat,you can instrt and delete link,input 'i' or 'd'\n");
printf("which one do you want to delete ,input i:\n");
scanf("%c,%d",&a,&i);
if(a=='i'||a=='I')
head=insert(head,i);
else if(a=='d'||a=='D')
head=dellink(head,i);
print(head);
}