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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started