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
// 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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
