List MakeEmpty(){
List L=(List)malloc(sizeof(struct LNode)); //malloc来创建
memset(L->Data,0,sizeof(L->Data));
L->Last=-1;
return L;
}
Position Find( List L, ElementType X ){
for(int i=0;i<=L->Last;i++){
if(L->Data[i]==X)
return i;
}
return ERROR;
}
bool Insert( List L, ElementType X, Position P ){
if(L->Last==MAXSIZE-1) { //先判断是都满,后判断是否违规
printf("FULL");
return false;
}
else if(P>L->Last+1||P<0){ //插入的位置最多到最后的位置的后面
printf("ILLEGAL POSITION");
return false;
}
else{
for(int i=L->Last;i>=P;i--){
L->Data[i+1]=L->Data[i];
}
L->Data[P]=X;
L->Last++;
return true;
}
}
bool Delete( List L, Position P ){
if(P>L->Last||P<0){
printf("POSITION %d EMPTY",P);
return false;
}
else{
for(int i=P;i<L->Last;i--){
L->Data[i]=L->Data[i+1];
}
L->Last--;
return true;
}
}
6-2 顺序表操作集 (20 分)
最新推荐文章于 2022-02-10 20:45:15 发布
2722

被折叠的 条评论
为什么被折叠?



