单链表无法输出
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
typedef struct Lnode{
int data;
struct Lnode *next;
int length;
}Lnode;
void list_create(Lnode *L);
void list_insert(Lnode *L,int i);
void list_delete(Lnode *L,int i);
void get_tail_data(Lnode L,int *e);
void print(Lnode L);
int main(void)
{
Lnode L;
list_create(&L);
print(L);
}
void list_create(Lnode *L)
{
int i,n;
Lnode *p;
L=(Lnode *)malloc(sizeof(Lnode));
if(L==NULL){
exit(-1);
}
L->next=NULL;
printf("Input the length of the list:\n");
scanf("%d",&n);//the next node is null
for(i=1;i<=n;i++){
printf("Input data%d:",i);
p=(Lnode *)malloc(sizeof(Lnode));
scanf("%d",&p->data);
++L->length;
L->next=p;//add the next node
p->next=L->next;
}
printf("The length of the list is %d\n",L->length);
}//CreateList_l
void print(Lnode L)
{
Lnode *p;
p=&L;
printf("Now the datas int the linked list is\n");
for(p=p->next;p!=NULL;p=p->next){
printf("%d ",*(p->data));//Linked_list.c:52: error: invalid type argument of ‘unary *’ (have ‘int’)
printf("\n");
}
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
typedef struct Lnode{
int data;
struct Lnode *next;
int length;
}Lnode;
void list_create(Lnode **L);
void list_insert(Lnode *L,int i);
void list_delete(Lnode *L,int i);
void get_tail_data(Lnode L,int *e);
void print(Lnode *L);
int main(void)
{
Lnode *L;
list_create(&L);
print(L);
}
void list_create(Lnode **L)
{
int i,n;
Lnode *p;
*L=(Lnode *)malloc(sizeof(Lnode));
if(L==NULL){
exit(-1);
}
(*L)->next=NULL;
(*L)->length = 0;
printf("Input the length of the list:\n");
scanf("%d",&n);//the next node is null
for(i=1;i<=n;i++){
printf("Input data%d:",i);
p=(Lnode *)malloc(sizeof(Lnode));
scanf("%d",&p->data);
++((*L)->length);
p->next=(*L)->next;
(*L)->next=p;//add the next node
}
printf("The length of the list is %d\n",(*L)->length);
}//CreateList_l
void print(Lnode *L)
{
Lnode *p;
p=L;
printf("Now the datas int the linked list is\n");
for(p=p->next;p!=NULL;p=p->next){
printf("%d ",p->data);//Linked_list.c:52: error: invalid type argument of ‘unary *’ (have ‘int’)
printf("\n");
}
}
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
typedef struct Lnode{
int data;
struct Lnode *next;
int length;
}Lnode;
void list_create(Lnode *L);
void list_insert(Lnode *L,int i);
void list_delete(Lnode *L,int i);
void get_tail_data(Lnode L,int *e);
void print(Lnode *L);
int main(void)
{
Lnode *L;
L=(Lnode *)malloc(sizeof(Lnode));
if(L==NULL){
exit(-1);
}
L->next=NULL;
L->length = 0;
list_create(L);
print(L);
}
void list_create(Lnode *L)
{
int i,n;
Lnode *p;
printf("Input the length of the list:\n");
scanf("%d",&n);//the next node is null
for(i=1;i<=n;i++){
printf("Input data%d:",i);
p=(Lnode *)malloc(sizeof(Lnode));
scanf("%d",&p->data);
++(L->length);
p->next=L->next;
L->next=p;//add the next node
}
printf("The length of the list is %d\n",L->length);
}//CreateList_l
void print(Lnode *L)
{
Lnode *p;
p=L;
printf("Now the datas int the linked list is\n");
for(p=p->next;p!=NULL;p=p->next){
printf("%d ",p->data);//Linked_list.c:52: error: invalid type argument of ‘unary *’ (have ‘int’)
printf("\n");
}
}
L->next=p;//add the next node
p->next=L->next;