c语言中k1=k1 lt k2怎么算,设顺序表L中的数据元素递增有序,试编写算法删除表中所有大于k1而小于k2的元素(k1<k2)...

#include

#include

#include

#include

#define LIST_INIT_SIZE 100     //max size

#define LISTINCREMENT 10    //add size

typedef int ElemType;

struct SQLIST

{

ElemType *elem;        //the address

int length;        //current size

int listsize;        //current memory

};

//init list

int InitList(struct SQLIST *L)

{

L->elem = (ElemType *)malloc(sizeof(ElemType) * LIST_INIT_SIZE);

if(!L->elem)

perror("malloc error");

L->length = 0;

L->listsize = LIST_INIT_SIZE;

return 1;

}

void DeleteList(ElemType key1, ElemType key2, struct SQLIST *L)

{

int i,j = 0;

int k;

int len = L->length;

if(key1 < key2 || key1 > L->elem[0] || key2 < L->elem[len])

{

for(i = 0; i< len; i++)

{

if(L->elem[i] > key1 && L->elem[i] < key2)

{

for(k=i;k

L->elem[k] = L->elem[k+1];

len--;

i--;

}

}

}

/*else if(key1 > key2 || key1 < L->elem[length] || key2 > L->elem[0])

{

while(L->elem[i] > key2 && L->elem[i] < key1)

{

L->elem[i] = L->elem[i+1];

i++;

}

}*/

L->length = len;  //last length;

}

int main(void)

{

int i, j;

int array[]= {1,2,3,4,5,6,7,8,9,10};

struct SQLIST SqList;

if(InitList(&SqList) != 1)

perror("init error");

for(i=0; i

SqList.elem[i] = array[i];

SqList.length = sizeof(array)/sizeof(ElemType);

DeleteList(3, 8, &SqList);

for(j=0;j

printf("%d", SqList.elem[j]);

return 0;

}

这是我自己写的 你参考下吧  有不懂的再来问我吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值