?? vector_perm.h
字號(hào):
// vector_perm.h
#include<vector>
#ifndef __VECTOR_PERM_H_
#define __VECTOR_PERM_H_
//recursive template permutation function
//Note : func parameters must always be vector<T> !
template <typename T, typename Func>
void vector_permutation(std::vector<T>& now,
std::vector<T> next, Func func)
{
int size=now.size();
if(size>0)
{
for(int cnt=0; cnt<size;++cnt)
{
std::vector<T> vt;
std::vector<T>::const_iterator it=now.begin();
for(int cnt1=0;cnt1<size;++cnt1)
{
if(cnt1==cnt)
{
++it;
continue;
}
else
vt.push_back(*it);
++it;
}
std::vector<T>::const_iterator it1=now.begin();
--it1;
for(int cnt2=0;cnt2<=cnt;++cnt2)
{
++it1;
}
next.push_back(*it1);
vector_permutation(vt,next,func);
next.pop_back();
}
}
else
{
func(next);
}
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -