马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<malloc.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L)
{
L.elem=new ElemType(MAXSIZE);
if(!L.elem) exit(ERROR);
L.length=0;
return OK;
}
int Load_Sq(SqList &L)
int i;
if(L.length==0) printf("The List is empty!");
{
printf("The List is: ");
for(i=0;i<L.length;i++) printf("%d ",L.elem);
}
printf("\n");
return OK;
}
int ListInsert_Sq(SqList &L,int i,int e)
{
int j;
if(i<1||i>L.length+1)
return ERROR;
if(L.length==MAXSIZE) return ERROR;
for(j=L.length-1;j>=i-1;j--)
L.elem[j+1]=L.elem[j];
L.elem[i-1]=e;
++L.length;
return OK;
}
int ListDelete_Sq(SqList &L,int i, int &e)
{
int j;
if(i<1||i>L.length+1)
return ERROR;
for(j=i-1;j<L.length;j++)
L.elem[j]=L.elem[j+1];
--L.length;
return OK;
}
int main()
{
SqList T;
int a, i;
ElemType e, x;
if(T.elem)
{
printf("A Sequence List Has Created.\n");
}
while(1)
{
printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
scanf("%d",&a);
switch(a)
{
case 1: scanf("%d%d",&i,&x);
if(i<1||i>T.length+1) printf("Insert Error!\n"); // 判断i值是否合法
else printf("The Element %d is Successfully Inserted!\n", x);
break;
case 2: scanf("%d",&i);
if(i<1||i>T.length+1) printf("Delete Error!\n"); // 判断i值是否合法
else printf("The Element %d is Successfully Deleted!\n", e);
break;
case 3: Load_Sq(T);
break;
case 0: return 1;
}
}
}
我改好的,没有错误和警告了
#include <stdio.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
#include <stdlib.h>
#define MAXSIZE 50
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList *L)
{
L->elem = (int*)malloc(MAXSIZE);
if(!L->elem) exit(ERROR);
L->length=0;
return OK;
}
int Load_Sq(SqList *L)
{
int i;
if(L->length==0)
printf("The List is empty!");
else
{
printf("The List is: ");
for(i=0;i<L->length;i++) printf("%d ",L->elem);
}
printf("\n");
return OK;
}
int ListInsert_Sq(SqList *L,int i,int e)
{
int j;
if(i<1||i>L->length+1)
return ERROR;
if(L->length==MAXSIZE) return ERROR;
for(j=L->length-1;j>=i-1;j--)
L->elem[j+1]=L->elem[j];
L->elem[i-1]=e;
++L->length;
return OK;
}
int ListDelete_Sq(SqList *L,int i, int *e)
{
int j;
if(i<1||i>L->length+1)
return ERROR;
for(j=i-1;j<L->length;j++)
L->elem[j]=L->elem[j+1];
--L->length;
return OK;
}
int main()
{
SqList T;
int a, i;
ElemType e, x;
if(T.elem)
{
printf("A Sequence List Has Created.\n");
}
while(1)
{
printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
scanf("%d",&a);
switch(a)
{
case 1: scanf("%d%d",&i,&x);
if(i<1||i>T.length+1) printf("Insert Error!\n"); // 判断i值是否合法
else printf("The Element %d is Successfully Inserted!\n", x);
break;
case 2: scanf("%d",&i);
if(i<1||i>T.length+1) printf("Delete Error!\n"); // 判断i值是否合法
else printf("The Element %d is Successfully Deleted!\n", e);
break;
case 3: Load_Sq(&T);
break;
case 0: return 1;
}
}
}
|