前天在写线性表的时候,在测试过程中发现销线性表的时候报了一个这样的错:

报的错误是:HEAP CORRUPTION DETECTED: before Normal block (#50) at 0x00392BF8.     CRT detected that the application wrote to memory before start of heap  buffer.

 

结果找了半天,是因为在删除元素的时候,将指针移动到堆初始位置的以下去了,结果报了这个错。

修改好后的delete函数为:

 

/* 初始条件:顺序线性表L已存在,1≤i≤ListLength */
/* 操作结果:在L中第i个位置删除数据元素,并用e返回,L的长度减1 */
Status ListDelete(SqList *L,int i,ElemType *e)
{
    ElemType *p;

    int j=1;

    if(i<1 || i>L->length)

    {

        return ERROR;

    }



    p=L->data+i-1;

    *e = *p;

    while(j<=L->length-i)

    {

        *p++=*(p+1);

        j++;

    }

    

    L->length--;

    return OK;
}

 

相关文章:

  • 2022-12-23
  • 2020-10-23
  • 2022-12-23
  • 2021-08-13
  • 2021-09-05
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
猜你喜欢
  • 2021-07-26
  • 2021-10-26
  • 2021-06-27
  • 2022-01-28
  • 2021-08-12
  • 2021-08-13
  • 2021-12-19
相关资源
相似解决方案