关于链表逆置 这样编译后 error C2236: unexpected 'struct' 'node' 代码我能看懂但是不知道怎么修改。。。
#include<stdio.h>#include<stdlib.h>structnode{intdata;structnode*next;}structnode*rev...
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
}
struct node * reverse(struct node *head)
{
struct node *p,*q;
p=head->next;
head->next=NULL;
q=p->next;
while(p!=NULL)
{
p->next=head->next;
head->next=p;
p=q;
if(q!=NULL)
q=q->next;
}
return(head);
}
void main()
{
struct node *head,*tail,*p,*q;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)
break;
p->next=NULL;
tail->next=p;
tail=p;
}
reverse(head);
q=head;
while(q->next!=NULL)
{
printf("%d ",q->next->data);
q=q->next;
}
printf("%d\n",q->next->data);
} 展开
#include <stdlib.h>
struct node
{
int data;
struct node *next;
}
struct node * reverse(struct node *head)
{
struct node *p,*q;
p=head->next;
head->next=NULL;
q=p->next;
while(p!=NULL)
{
p->next=head->next;
head->next=p;
p=q;
if(q!=NULL)
q=q->next;
}
return(head);
}
void main()
{
struct node *head,*tail,*p,*q;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)
break;
p->next=NULL;
tail->next=p;
tail=p;
}
reverse(head);
q=head;
while(q->next!=NULL)
{
printf("%d ",q->next->data);
q=q->next;
}
printf("%d\n",q->next->data);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询