c语言中重定义问题
这是一个链表问题我自己写的增加任意位置的链表add函数但是报错errorC2086:'pood':redefinition请问这是怎么回事?这是程序:#include<s...
这是一个链表问题 我自己写的增加任意位置的链表 add函数但是报错error C2086: 'pood' : redefinition 请问这是怎么回事? 这是程序:
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[20];
struct student *next;
};
struct student *create(int n) //创建节点
{
int i;
struct student *head,*p_end,*p_new;
head=NULL;
for(i=0;i<n;i++)
{
p_new=(struct student *)malloc(sizeof(struct student));
if(p_new==NULL)
{
printf("第%d个学生结点分配失败",i+1);
break;
}
printf("输入第%d个学生的学号",i+1);
scanf("%d",&p_new->num);
printf("输入第%d个学生的姓名",i+1);
scanf("%s",p_new->name);
printf("\n");
if(i==0)
{
head=p_new;
p_end=p_new;
}
else
{
p_end->next=p_new;
p_new->next=NULL;
p_end=p_new;
}
}
return head;
}
void add(struct student *head,int n)
{
int i=0;
struct student *pood;
struct student *m;
m=head;
struct student *pood=(struct student *)malloc(sizeof(struct student));//插入新的结点
if(pood!=NULL)
{
printf("插入新的结点:\n");
scanf("%d",&pood->num);
scanf("%s",pood->name);
while(i++<n&&m!=NULL)
{
pood=m;
m=m->next;
}
if(m!=NULL)
{
pood->next=m->next;
m->next=pood;
}
}
else
{
printf("结点内存分配失败!");
}
}
void delete_node(struct student *head,int index) //删除结点
{
int i=0;
struct student *p;
struct student *q;
p=head;
while(i++<index&&p!=NULL)
{
q=p;
p=p->next;
}
if(p!=NULL)
{
q->next=p->next;
free(p);
}
}
void printf_info(struct student *head)
{
int count=1;
struct student *p=head;
while(p!=NULL)
{
printf("第%d个学生信息==学号:%d,姓名:%s\n",count++,p->num,p->name);
p=p->next;
}
printf("\n");
}
int main()
{
printf("创建3个结点的链表:\n");
struct student *head=create(3);
printf("插入结点前:\n");
printf_info(head);
add(head,2);
printf_info(head);
printf("删除结点后:\n");
delete_node(head,1);
printf_info(head);
return 0;
} 展开
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[20];
struct student *next;
};
struct student *create(int n) //创建节点
{
int i;
struct student *head,*p_end,*p_new;
head=NULL;
for(i=0;i<n;i++)
{
p_new=(struct student *)malloc(sizeof(struct student));
if(p_new==NULL)
{
printf("第%d个学生结点分配失败",i+1);
break;
}
printf("输入第%d个学生的学号",i+1);
scanf("%d",&p_new->num);
printf("输入第%d个学生的姓名",i+1);
scanf("%s",p_new->name);
printf("\n");
if(i==0)
{
head=p_new;
p_end=p_new;
}
else
{
p_end->next=p_new;
p_new->next=NULL;
p_end=p_new;
}
}
return head;
}
void add(struct student *head,int n)
{
int i=0;
struct student *pood;
struct student *m;
m=head;
struct student *pood=(struct student *)malloc(sizeof(struct student));//插入新的结点
if(pood!=NULL)
{
printf("插入新的结点:\n");
scanf("%d",&pood->num);
scanf("%s",pood->name);
while(i++<n&&m!=NULL)
{
pood=m;
m=m->next;
}
if(m!=NULL)
{
pood->next=m->next;
m->next=pood;
}
}
else
{
printf("结点内存分配失败!");
}
}
void delete_node(struct student *head,int index) //删除结点
{
int i=0;
struct student *p;
struct student *q;
p=head;
while(i++<index&&p!=NULL)
{
q=p;
p=p->next;
}
if(p!=NULL)
{
q->next=p->next;
free(p);
}
}
void printf_info(struct student *head)
{
int count=1;
struct student *p=head;
while(p!=NULL)
{
printf("第%d个学生信息==学号:%d,姓名:%s\n",count++,p->num,p->name);
p=p->next;
}
printf("\n");
}
int main()
{
printf("创建3个结点的链表:\n");
struct student *head=create(3);
printf("插入结点前:\n");
printf_info(head);
add(head,2);
printf_info(head);
printf("删除结点后:\n");
delete_node(head,1);
printf_info(head);
return 0;
} 展开
4个回答
展开全部
add这个函数名前面已经用过了或者本身是系统定义的函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有两个struct student *pood
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JS
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询