简体   繁体   English

C ++自定义树的某些迭代后崩溃

[英]crash after some iteration of a c++ custom tree

I'm writing a simple sliding tiles (3x3) solver. 我正在编写一个简单的滑动图块(3x3)求解器。 It's not the best approach for sure i just generate all the possible configuration but I don't know why during the execution my pc freeze and I must manuallly restart. 当然,这不是最好的方法,我只是生成所有可能的配置,但是我不知道为什么在执行过程中我的PC冻结,我必须手动重新启动。 the's the main loop 这是主循环

while(!(tree->s==final))
{ 
    //copy it in tree   

    expand_node(tree);
    //check if in open then add if not
    it++;
}      
print_s(tree->s);

PS: I compiled everything with PS:我用

g++ -Wall -Wextra -std=c++11 main.cpp

Inside your range based for loops you are adding to the list: 在基于范围的for循环内,您将添加到列表中:

for(auto v : open)
    if(!(v.s==tree->childs[i].s))
        open.push_back(tree->childs[i]);

This will cause the list to grow and trigger another iteration until all the memory on your machine is exhausted. 这将导致列表增加并触发另一个迭代,直到计算机上的所有内存用完为止。 Your machine probably doesn't freeze just gets extremely slow whilst your OS is swapping memory to disk. 在操作系统将内存交换到磁盘时,您的计算机可能不会冻结,只会变得非常慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM