Question: main.cpp #include source.h /* printPermutation -- print a permutation of an array of char *'s */ static void printPermutation( int indices[], int nIndices, void *userArg)

main.cpp

#include "source.h" /* printPermutation -- print a permutation of an array of char *'s */ static void printPermutation( int indices[], int nIndices, void *userArg) { int i; char **syms = userArg; for (i = 0; i < nIndices; i++) printf("%s ", syms[indices[i]]); printf(" "); } int main(int argc, char *argv[]) { genPerms(argc-1, printPermutation, argv+1); return 0; }

...................................................................

source.h

extern void genPerms(int nElems, void (*handlePerm)(int elems[], int nElems, void *userArg), void *userArg);

......................................................................

source.cpp

#include /* * WARNING: This version of the program contains at least one bug! */ int level; enum { N_ELEM = 3, NOT_DONE = -1 }; int val[N_ELEM]; void recur(int k) { int i; val[k] = level; level++; if (level == N_ELEM) {

for (i = 0; i < N_ELEM; i++) printf("%d ", val[i]); printf(" "); } for (i = 0; i < N_ELEM; i++) if (val[i] == NOT_DONE) recur(i); level--;

val[k[ == NOT_DONE } int main(int argc, char *argv[]) { int i; level = 0; for (i = 0; i < N_ELEM; i++) val[i] = NOT_DONE; for (i = 0; i < N_ELEM; i++) recur(i); return 0; }

help me to complete permutation by editing source.cpp as per 1st and 2nd part requirement (don't make any change in first and second section).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!