#include #include #include #include const int size; int A[size], B[size], TEMP[size]; int number; void PRINT() { for ( int x = 0; x < number; x++ ) { if ( B[x] != 0 ) { cout << B[x] << setw(3); } } cout << endl; } /*void SELECT() { int a = 0; int b; for (int i = 0; i < number; i++) { b = 0; while ( (b < a) && (TEMP[b] != B[i]) ) b++; if (b >= a) { TEMP[a] = B[i]; a++; } } }*/ void BACKTRACK ( int i ) { for ( int j = 0; j < number; j++ ) { B[i] = A[j]; for ( int K = i+1; K < number; K++ ) { B[K] = 0; } if ( i == number - 1 ) { //SELECT(); PRINT(); cin.get(); } else { BACKTRACK ( i + 1 ); } } } int main() { cout << "How many element would you like: "; cin >> number; int x = 0; do { cout << "Enter the element " << x + 1 << " : "; cin >> A[x]; x++; cout << endl; } while ( x < number ); for ( int x = 0; x < number; x++ ) B[x] = 0; BACKTRACK (0); return 0; system ("PAUSE"); }