主题:链表
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "stdlib.h"
typedef struct lst
{
struct lst *next;
int data;
}Lst;
//初始化
Lst *initialize(){
Lst *head=NULL;
head=(Lst *)malloc(sizeof(Lst));
head->next=NULL;
return head;
}
//输出
void outLst(Lst *head)
{
Lst *q;
q=head;
do
{
q=q->next;
printf("%d->",q->data);
}while(q->next==NULL);
}
//输入
void inLst(Lst *head,int m)
{
Lst *q=NULL;
Lst *n=NULL;
n=(Lst *)malloc(sizeof(Lst));
n->data=m;
q=head;
while(q->next!=NULL)
{
q=q->next;
}
q->next=n;
}
void main()
{
Lst *head;
int d;
head=initialize();
scanf("%d",&d);
while(d!=-1)
{
inLst(head,d);
scanf("%d",&d);
};
outLst(head);
}
请问各位大侠,哪里错了,刚输入两个数据就出错了.....
#include "stdio.h"
#include "stdlib.h"
typedef struct lst
{
struct lst *next;
int data;
}Lst;
//初始化
Lst *initialize(){
Lst *head=NULL;
head=(Lst *)malloc(sizeof(Lst));
head->next=NULL;
return head;
}
//输出
void outLst(Lst *head)
{
Lst *q;
q=head;
do
{
q=q->next;
printf("%d->",q->data);
}while(q->next==NULL);
}
//输入
void inLst(Lst *head,int m)
{
Lst *q=NULL;
Lst *n=NULL;
n=(Lst *)malloc(sizeof(Lst));
n->data=m;
q=head;
while(q->next!=NULL)
{
q=q->next;
}
q->next=n;
}
void main()
{
Lst *head;
int d;
head=initialize();
scanf("%d",&d);
while(d!=-1)
{
inLst(head,d);
scanf("%d",&d);
};
outLst(head);
}
请问各位大侠,哪里错了,刚输入两个数据就出错了.....