-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