十万火急!!!高手帮忙啊(关于数据结构的一个程序)
我们数据结构老师要求我们交实验的程序,但是现在还没搞出来,请大家来帮帮我吧,谢谢了!题目是
试验一: 设某线性表数据元素的类型为整型,以顺序表为存储结构。试编程实现:
⑴ 线性表置空
⑵ 求线性表长度
⑶ 数据元素的插入操作
⑷ 数据元素的删除操作
⑸ 显示线性表中的全部元素
我的程序是
#include<STDIO.H>
#include<MALLOC.H>
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 2
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define TRUE 1
#define FALSE 0
#define NULL 0
typedef int ElemType
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList(SqList *L)
{
(*L).elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!(*L).elem)
exit(OVERFLOW);
(*L).length=0;
(*L).listsize=LIST_INIT_SIZE;
return OK;
}
Status ClearList(SqList *L)
{
(*L).length=0;
return OK;
}
int ListLength(SqList L)
{
return L.length;
}
Status ListInsert(SqList *L,int i,ElemType e)
{
ElemType *newbase,*q,*p;
if(i<1||i>(*L).length+1)
return ERROR;
if((*L).length>=(*L).listsize)
{
newbase=(ElemType *)realloc((*L).elem,((*L).listsize+LISTINCREMENT)*sizeof(ElemType));
if(!newbase)
exit(OVERFLOW);
(*L).elem=newbase;
(*L).listsize+=LISTINCREMENT;
}
q=(*L).elem+i-1;
for(p=(*L).elem+(*L).length-1;p>=q;--p)
*(p+1)=*p;
*q=e;
++(*L).length;
return OK;
}
Status ListDelete(SqList *L,int i,ElemType *e)
{
ElemType *p,*q;
if(i<1||i>(*L).length)
return ERROR;
p=(*L).elem+i-1;
*e=*p;
q=(*L).elem+(*L).length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
(*L).length--;
return OK;
}
Status displist(SqList L)
{
ElemType *p;
p=L.elem;
while(p!=NULL)
{p++;
printf("%d\n",*p);
}
main()
{int n,i,e;
sqlist *L;InitList(*L);
printf("1Clear the List2the Length of List3insert element4Delete the element5show all the element");
printf("\nPlease choose a num!");
scanf("%d",&n);
switch(n)
{case 1:printf("Clear the List");
ClearList(*L);break;
case 2:printf("ClearList") ;
ListLength(*L);break;
case 3:printf("insert element\nplease input a element");
scranf("%d%d",&i,&e);ListInsert(*L,i,e);break;
case 4:printf("Delete the element");
scranf("%d%d",&i,&e);ListDelete(*L,i,e);break;
case 5;printf("show all the element");
displist(*L);
}
}
但是我在TC2.0下编译不能通过,提示错误为:
c1:unable to open include file 'stdio.h'
c2:unable to open include file 'malloc.h'
c12:declaration error syntax
c20:declaration error syntax