逆序创建单链表

#include<stdio.h>
typedef int A;
typedef struct LNode
{
 A data;
 struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList &L,A a[],int n)
{
 int i;
 L=NULL;
 for(i=n-1;i>=0;i--)
 {
  LinkList s=new LNode;
  s->data=a[i];
  s->next=L;
  L=s;
 }
}
int main()
{ 
 int  n,a[1000],i;     //要确定数组a的大小int *a不行。
    scanf("%d",&n);
 for(i=n-1;i>=0;i--)
  scanf("%d",&a[i]);
 LinkList L ;
 CreateList(L,a,n);
 while(L)
 {
  printf("%d ",L->data) ;
        L = L->next ;
    }
 printf("
");
    return 0 ;
}


 

原文地址:https://www.cnblogs.com/NYNU-ACM/p/4237359.html