#define OK 1
#define NULL 0
#define ERROR 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCRENENT 10
typedef int ElemType;
typedef int status;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode ,*LinkList;
#include
#include
#include
void Creat_List(LinkList &L,int n)
{
LinkList p,q;
L=(LinkList)malloc(sizeof(LNode));
L->next= NULL;p=L;
for(int i=0;i
q=(LinkList)malloc(sizeof(LinkList)) ;
scanf("%d",&q->data);
p->next=q;
p=q;
}
if (q!=NULL) q->next=NULL;
}
void Print(LinkList p)
{
while(p!=NULL)
{
printf("%3d",p->data);
p=p->next;
}
}
void main()
{
int n;
LinkList L,p;
printf("\n请输入线形表的初始长度:");
scanf("%d",&n);
printf("请输入各个元素:\n");
Creat_List(L,n);
printf("链表的初始化后为:\n");
p=L->next;
Print(p);
printf("\n");
}
看看能运行吗
可能有编译错误,你自己改下
#include
#include
struct {
int value;
Node* next;
} Node;
int
main(void) {
char line[256];
struct Node* n;
while (1) {
printf("enter a number");
scanf("%s\n",line);
if (strlen(line) == 0) break;
struct Node* l = n;
n = (struct Node*)malloc(sizeof(struct Node));
n->next = l;
n->value = atoi(line);
}
while (n != NULL) {
printf("%d\n",n->value);
n = n->next;
}
}
死就死吧