删除线性表 函数

来源:百度知道 编辑:UC知道 时间:2024/09/20 03:56:44
#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
#define SIZE 10
typedef struct{
datatype data[SIZE];
int len;
}XB;

//删除操作并可以通过指针el返回元素的值
int delxb(int loc,datatype *el,XB *l){
if(loc<1){
printf("del error of loc\n");
return 0;
}
else{
if(l->len<=0){
printf("del error of not len\n");
return 0;
}
else{
int j;
el = &l->data[loc-1];
for(j=loc;j<=l->len;j++){
l->data[j-1] = l->data[j];
}
l->len--;
return loc;
}
}
}

我些的一个删除线性表元素的函数 loc是 第几个位置的意思
在调用时出问题了 提示是 printf("%d",*e); 这个语句
不知道什么原因 其他函数都正常
请问是怎么回事 或者应该怎么修改(彻底修改都行)

#include "xb_function.h"

void main(){
XB *l;
int *e;
l = (XB *)malloc(sizeof(datatype));
l

int delxb(int loc,datatype *el,XB *l){
if(loc<1){
printf("del error of loc\n");
return 0;
}
else if(l->len<=loc){ //
printf("del error of not len\n");
return 0;
}
else{
datatype *p,*q;
p = (*l).data+loc-1;
*el=*p;
q=(*l).data+(*l).len-1; //
for(++p;p<=q;++p){ //
*(p-1)=*p; // 你原来的基本问题没有,不过我习惯这样的。。 你给这一块,我没法调试,看有问题不?
}
(*l).len--;
return loc;
}
}
}

你把全部代码给出来啊。lnitxb,insertxb,printxb都没有啊。