Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please solve it with c++ and as it is asked . answer it as soon as possible. thank you Midrerm Project implement the algorithm, described
please solve it with c++ and as it is asked . answer it as soon as possible. thank you
Midrerm Project implement the algorithm, described below in the section titiled Permutation Algoritm, for generating alil he permutations of n distinct symbols .THE PROVIDED ALGORITHM MUST BE IMPLEMENTED You are NOT allowed to use any other algorithm. . This project must be an indvidual eftort Any apparent coliaboration in your submited work will be reported as Academic Misconduct . You must also use the following main program and are not permitted to change n * You must write a function named permute that (a) accepts a character array tr the symbols to be rearranged, (b) accepts an integer for the number of symbols in the array, and (c) returns 1 if a permutation was generated and 0 if a permutation could not be You are alowed to write helper functions you deem useful . The foilowing main program must be used char symbo ls[10] . ( 's. "M' int n-5 /l Generate pernutations until there are no more. int count while (hasNext) ( counte+ for (int i-o; i n; i..) { printf""symbols[i])i printff"Total pernutations return 8: sd", count); Step Description 1 The first time this algonthm is used so forth) 1b The symbols S, S, S, are the first permutation so return 1 to indicate a permutation has been generated The algornthm has aiready been used at least once Find a symboi that can be swapped 2 Set k to 1 3 Ifk > n then no symbol can be swapped so return 0 (no more permutations are possible) 4 Find the position (p) of Syin the current permutation 5 Ifp sn then swap the symbols at positions p and p-1 and retum 1 (a swap was possible and a new permutation has been The symbol cannot be swapped-return it to its initial position 6 Find the initial position 0) for S 7 Itprithen at Midrerm Project implement the algorithm, described below in the section titiled Permutation Algoritm, for generating alil he permutations of n distinct symbols .THE PROVIDED ALGORITHM MUST BE IMPLEMENTED You are NOT allowed to use any other algorithm. . This project must be an indvidual eftort Any apparent coliaboration in your submited work will be reported as Academic Misconduct . You must also use the following main program and are not permitted to change n * You must write a function named permute that (a) accepts a character array tr the symbols to be rearranged, (b) accepts an integer for the number of symbols in the array, and (c) returns 1 if a permutation was generated and 0 if a permutation could not be You are alowed to write helper functions you deem useful . The foilowing main program must be used char symbo ls[10] . ( 's. "M' int n-5 /l Generate pernutations until there are no more. int count while (hasNext) ( counte+ for (int i-o; i n; i..) { printf""symbols[i])i printff"Total pernutations return 8: sd", count); Step Description 1 The first time this algonthm is used so forth) 1b The symbols S, S, S, are the first permutation so return 1 to indicate a permutation has been generated The algornthm has aiready been used at least once Find a symboi that can be swapped 2 Set k to 1 3 Ifk > n then no symbol can be swapped so return 0 (no more permutations are possible) 4 Find the position (p) of Syin the current permutation 5 Ifp sn then swap the symbols at positions p and p-1 and retum 1 (a swap was possible and a new permutation has been The symbol cannot be swapped-return it to its initial position 6 Find the initial position 0) for S 7 Itprithen atStep 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