帮忙看一下,我的目的是要把数组给顺序表,还要在第一个位置插入7

来源:百度知道 编辑:UC知道 时间:2024/06/01 10:31:30
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 20
typedef struct
{
int a[MAXSIZE];
int last;
}List;

List *init_List()
{
List *l;
l=List*(malloc(sizeof(List)));
l->last=-1;
return l;
}

int Insert_List(List *l,int i, int x)
{
int j;
if(l->last=MAXSIZE-1)printf("The list is full");return -1;
if(i<1||i>=last+2) printf("The place is wrong");return 0;
for(j=l->last;j>=i-1;j--)
l->a[j+1]=l->a[j];
l->a[i-1]=x;
l->last++;
return 1;
}

你这哪是顺序表吧,你这是链表好不好
还有,把数组拷给链表,定义一个链表,链表的数据域只要一个int型就行了,不用是数组的,你是把数组里的值赋给链表的数据域,一个值就是一个结点,最后把结点串起来就行了,