给位大神你好,我最近在学习数据结构,但是遇到了一些问题,写的创建链表和读链表好像问题,帮忙看一看
											 程序代码:
程序代码:#include<stdio.h>
#include<stdlib.h>
typedef int elemtype;
typedef struct Node{
    elemtype data;
    struct Node *next;
}Node,*List; 
void outputlist(List L);    
Node* createlist(List L,int n);
int main()
{
  List h=NULL;
  printf("请输入5个数:");
  createlist(h,5);
  outputlist(h);
  return  0;
}
    
Node* createlist(List L,int n)
{
        
    L=(struct Node*)malloc(sizeof(Node));
    L->next=NULL;
    Node *r=L; 
    int i;
    for(i=0;i<n;i++){
        Node* p=(Node*)malloc(sizeof(Node));
        scanf("%d",&p->data);
        p->next=NULL;
        r->next=p;
        r=p;    
    } 
    return L; 
}
void outputlist(List L)
{
    
    Node* p;
    p=(Node*)malloc(sizeof(Node));
    p=L->next;
    while(p){
        printf("%d ",p->data);
        p=p->next; 
    } 
    
}
[此贴子已经被作者于2019-10-27 16:01编辑过]

 
											





 
	    
