顺序表的基本操作代码运行不报错但运行不了。

我用的gcc
代码运行不报错但就是执行不了。


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define list 10
#define max 10

typedef int Elemtype;
typedef struct sqlist 
{
    Elemtype *elem;
    int lenght;
    int listsize;
}*List;
void intlist (List L)
{
    L->elem=(Elemtype *)malloc(list*sizeof(Elemtype));
    L->lenght=0;
    L->listsize-max;
}

void creat(List L,int a[])
{
    intlist(L);
    int i;
    for(i=0;i<max;i++)
    {
        L->elem[i]=a[i];
        L->lenght++;
    }
}

int print(List L)
{
    int i;
    L->lenght=0;
    for(i=0;i<max;i++)
    {printf("%d",L->elem[i]);
    L->lenght--;}
    return 0;
}

int main(List L)
{
    int a[10]={1,2,3,4,5,6,7,8,9,0};
    creat(L,a);
    print(L);
    return 0;
}


int main居然还带个List参数???
creat用List类型作为参数,在函数内分配空间是不行的,不能修改外部L指针变量的地址的

 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define list 10
#define max 10
typedef int Elemtype;
typedef struct sqlist 
{
    Elemtype *elem;
    int lenght;
    int listsize;
}*List;
void intlist (List L)
{
    L->elem=(Elemtype *)malloc(list*sizeof(Elemtype));
    L->lenght=0;
    L->listsize=max;
}
List creat(List L,int a[])
{
    L = (List)malloc(sizeof(struct sqlist));
    intlist(L);
    int i;
    for(i=0;i<max;i++)
    {
        L->elem[i]=a[i];
        L->lenght++;
    }
    return L;
}
int print(List L)
{
    int i;
    for(i=0;i<max;i++)
    {printf("%d",L->elem[i]);
    L->lenght--;}
    return 0;
}
int main()
{
    List L;
    int a[10]={1,2,3,4,5,6,7,8,9,0};
    L = creat(L,a);
    print(L);
    return 0;
}