#ifndef _NODE_H_
#define _NODE_H_
typedef struct _node{
int value;
struct _node *next;
} Node;
#endif
typedef struct _list{
Node* head;
}List;
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
List list;
Node *head=NULL;
int number;
list.head=NULL;
do{
scanf("%d",&number);
if(number!=-1){
add(&list,number);
}
}while(number!=-1);
return 0;
}
void add(List *plist,int number){
Node *p=(Node*)malloc(sizeof(Node));
p->value=number;
p->next=NULL;
Node *last;
last=*plist->head;
if(last){
while(last->next){
last=last->next;
}
last->next=p;
}else{
plist->head=p;
}
}
incompatible types when assigning to type 'struct Node* ' from type 'Node'
你题目的解答代码如下:
#ifndef _NODE_H_
#define _NODE_H_
typedef struct _node{
int value;
struct _node *next;
} Node;
#endif
typedef struct _list{
Node* head;
}List;
#include <stdio.h>
#include <stdlib.h>
void add(List *plist,int number); //在前面声明下
int main(void)
{
List list;
Node *head=NULL;
int number;
list.head=NULL;
do{
scanf("%d",&number);
if(number!=-1){
add(&list,number);
}
}while(number!=-1);
head = list.head;
while (head)
{
printf("%d\n", head->value);
head = head->next;
}
return 0;
}
void add(List *plist,int number){
Node *p=(Node*)malloc(sizeof(Node));
p->value=number;
p->next=NULL;
Node *last;
last=plist->head; //去掉plist前面的*号
if(last){
while(last->next){
last=last->next;
}
last->next=p;
}else{
plist->head=p;
}
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
Line #36改为
last = plist->head;