#include "combination.hpp" using namespace btb; #include using namespace std; void out (int a[5], int n) { for (int i = 0; i < n; ++i) cout << "\t" << a[i]; if (n != 5) { cout << "\t\t" << "[" << a[n]; for (int i = n + 1; i < 5; ++i) cout << "\t" << a[i]; cout << "]"; } cout << endl; } int main() { int a[5] = {0, 1, 2, 3, 4}; cout << "the initial values are:" << endl; out (a, 5); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "select two elements from {0, 1, 2, 3, 4} by next::" << endl; do { out (a, 2); } while (next_combination(a, a+2, a+5)); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "now the array is:" << endl; out (a, 5); cout << "it becomes the original" << endl; cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "init_combination to largest(select two elements):" << endl; init_combination (a, a+2, a+5, false); out (a, 5); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "and then generate by previous(select two elements):" << endl; do { out (a, 2); } while (prev_combination(a, a+2, a+5)); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "test a sequence has equivalent elements" << endl; a[1] = 0; out (a, 5); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "adust it(select two elements):" << endl; adjust_combination (a, a+2, a+5); out (a, 5); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "go next(select two elements):" << endl; do { out (a, 2); } while (next_combination(a, a+2, a+5)); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "go previous, get largest sequence(select two elements):" << endl; prev_combination (a, a+2, a+5); out (a, 5); cout << "----------------------------- press ENTER to continue" << endl; cin.get(); cout << "final, generate all sequence by go previous:" << endl; do { out (a, 2); } while (prev_combination(a, a+2, a+5)); cout << "----------------------------- press ENTER the game over :)" << endl; cin.get(); }