-1
所以我得到了这段代码。问题是用for循环创建空列表并添加1个整数。然后我将这个列表传递给DFS函数,它说列表是空的。任何想法为什么发生这种情况?传递给函数的非空列表变为空
#include <list>
#include<vector>
#include <iostream>
using namespace std;
list<short> integer;
vector<list<short> > all;
void DFS(list<short> ingeter, int N)
{
if(integer.empty())
{
cout<<"IT IS EMPTY"<<endl;
return;
}
if(integer.size() > N || (integer.size() > 0 && (integer.front() == 0 || integer.back() % 2 == 0)))
{
return;
}
cout<<"size: "<<integer.size()<<endl;
all.push_back(integer);
for(short i = 0; i <= 9; ++i)
{
integer.push_back(i);
integer.push_front(i);
DFS(integer, N);
integer.pop_back();
integer.pop_front();
}
}
int main()
{
int N = 8;
for(short i = 0; i <= 9; ++i)
{
list<short> current;
current.push_back(i);
cout<<"size: "<<current.size()<<endl;
DFS(current, N);
}
return 0;
}
请不要只是放下一堆代码,并要求我们阅读它。编译一个简短的例子(http://sscce.org/)来代替这个问题。 – filmor
我缩短了它 – user1113314
SSCCEE中的'c'意味着可编译。这段代码不会编译。 – filmor