#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node* createlist()
{
int data;
struct node*p,*q=NULL,*h=NULL;
while(1)
{
if((data=getchar())!='\n'&&data!=32)
{
p=(struct node*)malloc(sizeof(struct node));
p->data =data;
if(h==NULL) /*the first tree*/
h=p;
else
q->next=p;
q=p;
}
else if(data=='\\')
break;
}
if(q!=NULL)
q->next =NULL;
return h;
}
int main()
{
struct node * h = createlist();
return 0;
displist();
}
int displist(struct node*h)
{
struct node*p =h;
while(p!=NULL)
{
printf("%4c",p->data);
p=p->next ;
}
}
{
struct node * h = createlist(); //这是调用创建链表函数,返回表头指针 给h
displist( h ); //这个函数调用 缺少了参数
return 0; //程序遇到Return命令就会返回函数调用者,若main中,就会返回系统,即程序退出
}
这是一个函数,返回类型是struct node*,那么struct node* h = createlist();就是让h等于createlist()函数返回的指针。
main函数中的
return 0;
displist();
displist()函数这样是不会执行的,因为return 0已经表示返回了。追问
那怎么操作啊。我网上找到一个
typedef struct NodeType
{
ElemType data;
struct NodeType *next;
} NodeType,*LinkType;
这个时候 linktype是带*的
void output(LinkType head)
,为什么调用的时候就没有 * 了呢,能不能加个Q.Q,我有好多问题,分数当然不是问题
可以 60 56 45324