对顺序表的部分操作(2)

/*功能为:删除顺序表中范围为[x,y]之间所有元素值,要求时间复杂度为O(n),空间复杂度为O(1)*/
void DeleElemRange(Sqlist *&L,ElemType x,ElemType y)
{
 int i=0,j=0;
 while(i<L->length)
 {
  if(!(L->data[i]>=x&&L->data[i]<=y))
  {
   L->data[j]=L->data[i];
   j++;
  }
  i++;
 }
 L->length=j;
}

你可能感兴趣的:(对顺序表的部分操作(2))