下載點:
完整檔案包,可直接執行 MLedit.exe
MLedit_0.1.0_complete.7z
精簡檔案包,適用於已安裝 CxxlMan2 開發環境懶人包,執行 "MLedit.exe - 捷徑 "
MLedit_0.1.0_simplify.7z
原始檔案包,適用於已安裝 CxxlMan2 開發環境懶人包,解壓到 C:\MySrc,支援 CMake 建立編譯專案
MLedit_0.1.0_Src.7z
以下為新版:
#include <functional> // std::function #include <memory> // std::shared_ptr #include <vector> #include <iostream> using namespace std; // n 取 r 做排列 // 採用逆時旋轉排列法 // 必須 n >= r class Permutation_nPr { // 回報結果 function<void(const shared_ptr<vector<unsigned char> > &, size_t)> m_Report; // 放置要排列的數字 shared_ptr <vector<unsigned char> > m_Digital_Array; // 要做排列的數目值 size_t m_r; void v(size_t n, size_t r) { if (r == 0) m_Report(m_Digital_Array, m_r); else v(n - 1, r - 1); for (size_t j = n; j > 0; --j) { { unsigned char tmp = m_Digital_Array->at(n); m_Digital_Array->at(n) = m_Digital_Array->at(j-1); m_Digital_Array->at(j - 1) = tmp; } if (r == 0) m_Report(m_Digital_Array, m_r); else v(n - 1, r - 1); { unsigned char tmp = m_Digital_Array->at(n); m_Digital_Array->at(n) = m_Digital_Array->at(j-1); m_Digital_Array->at(j - 1) = tmp; } } } public: Permutation_nPr( const function<void(const shared_ptr<vector<unsigned char> > &, size_t)> &Receive ):m_Report(Receive) {} void nPr(size_t n, size_t r) { m_r = r; m_Digital_Array = shared_ptr<vector<unsigned char> >(new vector<unsigned char>(n)); size_t i = n; while (i--) { m_Digital_Array->at(i) = i; } v(n - 1, r - 1); } }; class MsgShow { int N{1}; public: void ResetN(){N = 1;} void operator()( const shared_ptr<vector<unsigned char> > &Digital_Array, size_t r) { cout << N << ":\t"; for (size_t i = Digital_Array->size() - 1; r > 0; --i, --r) cout << (int)Digital_Array->at(i) << ' '; cout << endl; ++N; } }; int main() { MsgShow Report; Permutation_nPr P(Report); cout << '\n' << "4P3 排列:" << endl; Report.ResetN(); P.nPr(4,3); return 0; }
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <vector>
#include <iostream>
using namespace std;
// n 取 r 做排列
// 採用逆時旋轉排列法
// 必須 n >= r
class Permutation_nPr
{
// 回報結果
function<void(const shared_ptr<vector<unsigned char> > &, size_t)> m_Report;
// 放置要排列的數字
shared_ptr <vector<unsigned char> > m_Digital_Array;
// 要做排列的數目值
size_t m_r;
void v(size_t n, size_t r)
{
size_t i = n + 1;
while (i--)
{
if (r == 0)
m_Report(m_Digital_Array, m_r);
else
v(n - 1, r - 1);
unsigned char tmp = m_Digital_Array->at(n);
for (size_t j = n; j > 0; --j)
m_Digital_Array->at(j) = m_Digital_Array->at(j - 1);
m_Digital_Array->at(0) = tmp;
}
}
public: Permutation_nPr( const function<void(const shared_ptr<vector<unsigned char> > &, size_t)> &Receive ) :m_Report(Receive)
{}
void nPr(size_t n, size_t r)
{
m_r = r;
m_Digital_Array =
shared_ptr<vector<unsigned char> >(new vector<unsigned char>(n));
size_t i = n;
while (i--)
{
m_Digital_Array->at(i) = i;
}
v(n - 1, r - 1);
}
};
int N = 1;
void Show(const shared_ptr<vector<unsigned char> > &Digital_Array, size_t r)
{
cout << N << ":\t";
for (size_t i = Digital_Array->size() - 1; r > 0; --i, --r)
cout << (int)Digital_Array->at(i) << ' ';
cout << endl;
++N;
}
int main()
{
Permutation_nPr P(Show);
cout << "4P3 排列:" << endl;
N = 1;
P.nPr(4, 3);
return 0;
}
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <vector>
#include <iostream>
using namespace std;
// n 取 n 做排列
// 採用逆時旋轉排列法
class Permutation_nPn
{
// 回報結果
function<void(const shared_ptr<vector<unsigned char> > &)> m_Report;
// 放置要排的數字
shared_ptr <vector<unsigned char> > m_Digital_Array;
void v(size_t n)
{
if (n == 0)
m_Report(m_Digital_Array);
else
{
size_t i = n + 1;
while (i--)
{
v(n - 1);
unsigned char tmp = m_Digital_Array->at(n);
for (size_t j = n; j > 0; --j)
m_Digital_Array->at(j) = m_Digital_Array->at(j - 1);
m_Digital_Array->at(0) = tmp;
}
}
}
public: Permutation_nPn(
const function<void(const shared_ptr<vector<unsigned char> > &)>
&Receive
)
:m_Report(Receive)
{}
void nPn(size_t n)
{
m_Digital_Array = shared_ptr<vector<unsigned char> >(
new vector<unsigned char>(n));
size_t i = n;
while (i)
{
m_Digital_Array->at(i - 1) = i - 1;
--i;
}
v(n - 1);
}
};
int N = 1;
void Show(const shared_ptr<vector<unsigned char> > &Digital_Array)
{
cout << N << ":\t";
for (size_t i = Digital_Array->size(); i > 0; --i)
cout << (int)Digital_Array->at(i - 1) << ' ';
cout << endl;
++N;
}
int main()
{
Permutation_nPn P(Show);
cout << "4! 排列:" << endl;
N = 1;
P.nPn(4);
return 0;
}