代码应该如何写?
#include "stdafx.h"#include "stdio.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define OK 1
#define Error 0
#define OVERFLOW -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList &L)
{
int i;
L.elem = (ElemType * )malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (! L.elem) exit (OVERFLOW);
for(i=1;i<=5;i++)
{
scanf("%d",&L.elem[i-1]);
}
L.length = 5;
L.listsize = LIST_INIT_SIZE;
return OK;
}
Status PrintList_Sq(SqList L)
{
int i;
ElemType newbase;
printf("Linklist yuansu is:\n ");
for (i=1;i<=L.length;i++)
{
printf("%4d",L.elem[i-1]);
}
printf("\n");
return OK;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e)//插入函数应该如何编写代码?
{
return OK;
}
Status ListDelete_Sq(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;
}
int main(int argc, char* argv[])
{
SqList L;
ElemType e;
int select,i;
InitList_Sq(L);
PrintList_Sq(L);
ListDelete_Sq(L,i,e);
printf("input i:\n");
scanf("%d",&i);
if (ListDelete_Sq(L,i,e)==Error)
printf("i is error!\n");
else
PrintList_Sq(L);
return 0;
}