#include #include #include using namespace std; int compare(const void *a, const void * b) { return (*(char *)a - *(char *)b); } void swap(char* a, char* b) { char t = *a; *a = *b; *b = t; } void...

1 answer below »
C++ program, combine programs to a single cpp file making sure the output meets the assignment.Thank You


#include #include #include using namespace std; int compare(const void *a, const void * b) { return (*(char *)a - *(char *)b); } void swap(char* a, char* b) { char t = *a; *a = *b; *b = t; } void reverse(char str[], int l, int h) { while (l < h)="" {="" swap(&str[l],="" &str[h]);="" l++;="" h--;="" }="" }="" this="" function="" finds="" the="" index="" of="" the="" smallest="" character="" which="" is="" greater="" than="" 'first'="" and="" is="" present="" in="" str[l..h]="" int="" findceil(char="" str[],="" char="" first,="" int="" l,="" int="" h)="" {="" int="" ceilindex="l;" now="" iterate="" through="" rest="" of="" the="" elements="" and="" find="" the="" smallest="" character="" greater="" than="" 'first'="" for="" (int="" i="l" +="" 1;="" i=""><= h;="" i++)="" if="" (str[i]=""> first && str[i] < str[ceilindex])="" ceilindex="i;" return="" ceilindex;="" }="" void="" lexiographicpermutations(char="" p[])="" {="" get="" size="" of="" string="" int="" n="strlen(P);" sort="" the="" string="" in="" increasing="" order="" qsort(p,="" n,="" sizeof(p[0]),="" compare);="" print="" permutations="" one="" by="" one="" bool="" isfinished="false;" while="" (!isfinished)="" {="" print="" this="" permutation="" cout="">< p;="" find="" the="" largest="" index="" such="" p[i]="0;" --i)="" if="" (p[i]="">< p[i="" +="" 1])="" break;="" termination="" condition,="" means="" we="" just="" added="" the="" last="" permutation="" and="" we="" are="" done.="" if="" (i="=" -1)="" isfinished="true;" else="" {="" largest="" index="" such="" that="" p[j]="">p[i] int j = findCeil(P, P[i], i + 1, n - 1); cout < " i= " << i << " j= " << j << endl; // swap first and second characters swap(&p[i], &p[j]); // reverse the string reverse(p, i + 1, n - 1); } } } int main(){ char str[] = "1234"; lexiographicpermutations(str); return 0; } program 2 – generating permutations csc2400 assigned: 10/10/2018 due: 10/26/2018 (by 11:59 pm) description write a c++ program implemented in a single source file named permutations.cpp that uses two decrease- and-conquer algorithms for generating permutations. the two algorithms are johnson trotter and lexicographic permute. the pseudocode for these algorithms are provided in this assignment. each permutation should be printed to the screen in the specific way as the example output at the bottom of this assignment. johnson trotter lexicographic permute don’t cheat & get help make sure you review the “get help & don’t cheat!” section of our class syllabus so that you are not charged with academic misconduct. i am aware that many implementations of these algorithms are available online. however taking solutions off of websites and forums online and submitting them as your own work is considered cheating in csc2400. the assignment is to be able to create your own implementation of these algorithms, not simply just to find an implementation online. sample output note: i do want you to print out the arrow directions for the johnson trotter algorithm as shown in the output above. also, i do want the value for i & j to be3 printed out for the lexicographic algorithm. what to turn in zip your permutations.cpp file and then upload it to the program 2 assignment folder in ilearn by the due date. "="" i=" << i << " j=" << j << endl; // Swap first and second characters swap(&P[i], &P[j]); // reverse the string reverse(P, i + 1, n - 1); } } } int main(){ char str[] = " 1234";="" lexiographicpermutations(str);="" return="" 0;="" }="" program="" 2="" –="" generating="" permutations="" csc2400="" assigned:="" 10/10/2018="" due:="" 10/26/2018="" (by="" 11:59="" pm)="" description="" write="" a="" c++="" program="" implemented="" in="" a="" single="" source="" file="" named="" permutations.cpp="" that="" uses="" two="" decrease-="" and-conquer="" algorithms="" for="" generating="" permutations.="" the="" two="" algorithms="" are="" johnson="" trotter="" and="" lexicographic="" permute.="" the="" pseudocode="" for="" these="" algorithms="" are="" provided="" in="" this="" assignment.="" each="" permutation="" should="" be="" printed="" to="" the="" screen="" in="" the="" specific="" way="" as="" the="" example="" output="" at="" the="" bottom="" of="" this="" assignment.="" johnson="" trotter="" lexicographic="" permute="" don’t="" cheat="" &="" get="" help="" make="" sure="" you="" review="" the="" “get="" help="" &="" don’t="" cheat!”="" section="" of="" our="" class="" syllabus="" so="" that="" you="" are="" not="" charged="" with="" academic="" misconduct.="" i="" am="" aware="" that="" many="" implementations="" of="" these="" algorithms="" are="" available="" online.="" however="" taking="" solutions="" off="" of="" websites="" and="" forums="" online="" and="" submitting="" them="" as="" your="" own="" work="" is="" considered="" cheating="" in="" csc2400.="" the="" assignment="" is="" to="" be="" able="" to="" create="" your="" own="" implementation="" of="" these="" algorithms,="" not="" simply="" just="" to="" find="" an="" implementation="" online.="" sample="" output="" note:="" i="" do="" want="" you="" to="" print="" out="" the="" arrow="" directions="" for="" the="" johnson="" trotter="" algorithm="" as="" shown="" in="" the="" output="" above.="" also,="" i="" do="" want="" the="" value="" for="" i="" &="" j="" to="" be3="" printed="" out="" for="" the="" lexicographic="" algorithm.="" what="" to="" turn="" in="" zip="" your="" permutations.cpp="" file="" and="" then="" upload="" it="" to="" the="" program="" 2="" assignment="" folder="" in="" ilearn="" by="" the="" due="">
Answered Same DayOct 17, 2020

Answer To: #include #include #include using namespace std; int compare(const void *a, const void * b) { return...

Snehil answered on Oct 22 2020
155 Votes
My Work/permutations.cpp
My...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here