精通C语言和数据结构的高手请进

这是一段由.cpp格式更改到.c格式的程序 已经做了相应改动但是还是不能运行 请高手指教!!

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define ElemType int
typedef int Status;

//-----------------------------------------
#define LIST_INIT_SIZE 80
#define LISTINCREMENT 10

#include <stdio.h>
#include <stdlib.h>
typedef struct

{
ElemType * elem;
int length;
int listsize;
}SqList;

Status InitList_Sq(SqList *L) //结构初始化
{
L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if (!L->elem)
exit (OVERFLOW);
L->elem= 0;
L->listsize= LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq( SqList *L, int i, ElemType e )//在L的第i个元素之前插入新的元素e,1≤i≤LengthList(L)+1
{
if (i > L->length + 1 || i < 1)
return ERROR;
if ( L->length >= L->listsize)
{
ElemType * newbase = (ElemType *)realloc(L->elem, (LIST_INIT_SIZE + LISTINCREMENT)*sizeof(ElemType));
if (!newbase) exit( ERROR );
L->elem = newbase;
L->listsize += LISTINCREMENT;
}

{ElemType * p = L->elem + L->length - 1;
for (; p >= L->elem + i - 1; p--)
*(p + 1) = *p;
*++p = e;
}
++L->length;
return OK;
}

Status ListDelete_Sq( SqList *L, int i, ElemType *e )//删除L的第i个元素,并用e返回其值,L的长度减1,1≤i≤LengthList(L)
{
if (i > L->length || i < 1)
return ERROR;
e = *(L->elem + i -1);
for (ElemType * p = L->elem + i -1; p <= L->elem + L->length - 2; p++)
*p = *(p + 1);
--L->length;
return OK;
}

Status GetElem_Sq( SqList L, int i, ElemType *e )
{
if (i > L.elem || i < 1)
return ERROR;
e = *( L.elem + i - 1);
return OK;
}

void PrintList_Sq (SqList L)
{
ElemType * p = L.elem;
while (p <= L.elem + L.length - 1)
printf ("%d\t", *p++);
printf ("The length of the list is %d.\n",L.length);
}

void main( ){
int cur_e, next_e, pre_e, e,i;
SqList L;
InitList_Sq (&L);
int cond;
int num;
cond=1;
while (cond) {
printf("\n**************************\n");
printf(" 1 -------插入 \n");
printf(" 2 -------删除 \n");
printf(" 3 -------显示 \n");
printf(" 4 -------退出 \n");
printf("**************************\n");
scanf("%d",&num);
switch(num){
case 1:
printf("Please input the position: ");
scanf("%d",&i);
printf("Please input the data : ");
scanf("%d",&e);
ListInsert_Sq(L,i,e);
break;
case 2: break;
case 3: PrintList_Sq (L);break;
case 4: cond=0;break;
default: printf(" ERROR\n");
}
printf("\n");
}

}//顺序存储结构的顺序表实现

第1个回答  2009-03-31
105行:ListInsert_Sq(&L,i,e);
相似回答
大家正在搜