Question: my code coplier is cpp/ c++ #include using namespace std; // write the code that implemets the functions below // The swapchar doesn't print or

 my code coplier is cpp/ c++ #include using namespace std; //write the code that implemets the functions below // The swapchar doesn't

print or return any value, just swaps the 2 // characters at

my code coplier is cpp/ c++

index i and j in the array a of size n. void

#include using namespace std;

// write the code that implemets the functions below

// The swapchar doesn't print or return any value, just swaps the 2 // characters at index i and j in the array a of size n. void swapchar(char *a,int n,int i,int j){ // insert your code here }

// The swap function takes in an array a[], of size n, // and swaps the content of the array at indexes i and j. // It returns false if there is no swap (i.e. if i and j are the same) // and true otherwise. // If there is a swap, for example swapping the first two elements in // [4,3,2,1] it also prints: // swapped 3 and 4 and array is now [3,4,2,1] bool swap(int *a,int n,int i,int j) { // insert your code here return true; }

// write a function called selectionSort that sorts an array of ints // a, of size n, either in descending order (e.g., 5,4,3...) when up // is true, or in ascending order (e.g., 3,4,5...) when up is false. // Every time a swap is made, it should add 1 to the variable swaps // (note that if swap() returns false, it should not increase swaps). // Every time a comparison is made, it should add 1 to the variable // comparisons. At the end it should print swaps and comparisons. // Also, every time elements in the int array a is swapped, the same // elements in the char array s should also be swapped. // The sorting algorithm should be Selection Sort. void selectionSort(int*a,char*s,int n,bool up){ int comparisons=0,swaps=0; // insert your code here cout

// Write a function with the same requirements as selectionSort, // but the sorting algorithm should be Bubble Sort. void bubbleSort(int*a,char*s,int n,bool up){ int comparisons=0,swaps=0; // insert your code here cout

// leave the code below in main as it is, write code only in the above functions int main() { int a[10]={4,1,3,2,0}; char s[]="ebdcafghij"; string type="selection"; int n=5; //simple hardcoded test for debugging bool sortUp=true; selectionSort(a,s,5,true); cout

cin>>type>>n>>sortUp; for(int i=0;i>a[i];}

if (type=="selection") { selectionSort(a,s,n,sortUp); } else if (type=="bubble") { bubbleSort(a,s,n,sortUp); } else if (type=="insertion") { insertionSort(a,s,n,sortUp); } cout \ 71% 09 AM Questioin #include using namespace std; I write the code that implemets the functions below // The swapchar doesn't print or return any value, just swaps the 2 /I characters at index i and j in the array a of size n void 8 swapchar(char *a, int n, int i, int j){ // insert your code here 12 14 16 // The swap function takes in an array a], of size n I and swaps the content of the array at indexes i and /1 It returns false if there is no swap (i.e. if i and j are the same) /I and true otherwise /1 If there is a swap, for example swapping the first two elements in [4,3,2,1] it also prints: swapped 3 and 4 and array is now [3,4,2,1 17 19 bool swap(int *a, int n. int i, int j) { 20 // insert your code here return true 23 24 26 28 I write a function called selectionSort that sorts an array of ints I a, of size n, either in descending order (e.g., 5,4,3 /I is true, or in ascending order (e I Every time a swap is made, it should add 1 to the variable swaps I (note that if swap() returns false, it should not increase swaps) when up 3,4,5.) when up is false Every time a comparison is made, it should add 1 to the variable /I comparisons. At the end it should print swaps and comparisons 29 Also, every time elements in the int array a is swapped, the same /I elements in the char array s should also be swapped /I The sorting algorithm should be Selection Sort void 31 34 35 36 37 38 39 selectionsort(int*a,char*s,int n,bool up){ int comparisons-0, swaps-0 /1 insert your code here cout

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!