Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive Enumeration Example
// Example from Lecture 6 in class on recursive functions #include <iostream> using namespace std; void recursiveEnumeration(int *array, int start, int n) { static int permutationNumber = 0; for (int i=0; i<start; i++) cout << " "; cout << "Entering into recursiveEnumeration level: start = " << start << endl; if (start==(n-1)) { // print out answer for (int i=0; i<n; i++) { cout << " "; } cout << "** Permutation Number: " << ++permutationNumber << " is: "; for (int i=0; i<n; i++) { cout << array[i] << " "; } cout << "**" << endl; return; } for (int i=start; i<n; i++) { // make recursive call, note the change of the argument values // need to do swap here... recursiveEnumeration(array,start+1,n); // need to undo swap here... } for (int i=0; i<start; i++) cout << " "; cout << "Returning from recursiveSort level: start = " << start << endl; return; } int main() { int n, *array; cout << "Enter n: "; cin >> n; // create array of that size array = new int[n]; cout << endl << "n = " << n << endl << endl; cout << "Initial array = "; for (int i=0; i<n; i++) { array[i] = i+1; cout << array[i] << " "; } cout << endl; recursiveEnumeration(array, 0, n); cout << endl << "Done " << endl; return 0; }
run
|
edit
|
history
|
help
0
user defined exception
Set sub sequences.
applidiumResto_NicolasCarre
Mock Interview Question
Fundamentos de programación. Tema 7. Ejercicio 6.
Apple is not convertible to itself (clang 3.8.0)
Move Construction
HTML Timetable generator.cpp
Reference example
ArrayList Example Starter Code 2