search

Home  >  Q&A  >  body text

c++ - 为什么编译可以通过,执行时候却自动停止程序呢?顺序表类功能实现

函数打算实现两个List合并为一个List,这个顺序表不是链表,就是普通的数组。

上次一个CombineList里面的函数确实出现了错误,谢谢大家的提醒。
还有小弟第一次提问,不太会排版。好多的描述都没有显示出来。现在重新编辑,
我想实现的是两个List顺序表的合并,其中第一幅图给出了合并的算法。里面的那个k是错误的。没啥用,第二次的循环里面把k改为i。
每次程序运行时候就会卡死这里,并出现后面的图,具体啥原因我也不知道。希望大家能来帮帮我。

PHP中文网PHP中文网2773 days ago488

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 14:43:51

    There is a small possibility of overflow. Although you have changed mSize, it does not mean that the capacity of your list has really increased.

    In addition, in the second loop of the first code, I don’t understand why k appears.
    This k always remains unchanged, so even if the program does not crash, I guess your result is wrong.

    Then there is another possible reason, which is the problem of shallow copy and deep copy. You probably use new in your list, so this class has to implement the copy construction and assignment functions by itself, otherwise it may be deleted twice.

    Finally, let me complain. When debugging in VS, when it crashes, it will show which statement it crashed in. You can post this screenshot at least. The code is not posted in full. Others who want to help you debug have no way to start. .

    reply
    0
  • Cancelreply