
1. Using the following code c++ please insert a merge sort
2.compare the first code with a counter sort to see wish one is faster.
#include<iostream>
using namespace std;
// PLACE NAME HERE
// Function prototypes
void bubbleSortArray(int[], int);
const int SIZE = 5;
int main()
{
int values[SIZE] = { 9,2,0,11,5 };
// Displays the array before sorting
cout << "The values before the bubble sort is performed are: ";
for (int count = 0; count < SIZE; count++)
cout << values[count] << " ";
cout << endl;
// Sort the array in ascending order using bubble sort
bubbleSortArray(values, SIZE);
// Display the array after sorting
cout << "\n\nThe values after the bubble sort is performed are: ";
for (int count = 0; count < SIZE; count++)
cout << values[count] << " ";
return 0;
}
//******************************************************************
// bubbleSortArray
//
// task: to sort values of an array in ascending order
// data in: the array, the array size
// data out: the sorted array
//
//******************************************************************
void bubbleSortArray(int array[], int elems)
{
bool swap;
int temp;
int bottom = elems - 1; // Bottom indicates the end part of the
// array where the largest values have
// settled in order
do
{
swap = false;
for (int count = 0; count < bottom; count++)
{
if (array[count] > array[count + 1])
{ // The next three lines swap the two elements
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true; // Indicates that a swap occurred
}
// Display array at each each step
cout << "\nThe values are: TO BE IMPLEMENTED";
// Add code here to diplay the complete array at each step
// Hint: for-loop similar to the one in the main() function
for (int count = 0; count < SIZE; count++)
cout << array[count] << " ";
}
bottom--; // Bottom is decremented by 1 since each pass through
// the array adds one more value that is set in order
// Loop repeats until a pass through the array with no swaps occurs
} while (swap != false);
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- C PROGRAMMING Consider the following function: void sort(struct Employee * base[], int n, int (*compareFunc)(struct Employee ** , struct Employee **)){ qsort((void **)base, n, sizeof(void *), (int (*)(const void *,const void *))compareFunc);} Use the function above to answer the following questions: 1) What does the line in the provided sort function do? Describe each of the 4 arguments being passed to qsort, and explain why we need that rather strange cast for the fourth argument? 2) Describe generally how we could add a WHERE clause to list - which would allow us to see only specific employees with a certain characteristic. For example, " WHERE SALARY > 10000 " 3) Why does the compareFunc take 2 struct Employee ** parameters, as opposed to just 1 (struct Employee *)?arrow_forwardQuestions: There needs to be a dynamic array of Child that opposes with SCALE and is assigned to "familyTree". The createFamilyTree() function needs to be defined. Please see the C++ code.arrow_forwardC++ Sort a vector Define a function named SortVector that takes a vector of integers as a parameter. Function SortVector() modifies the vector parameter by sorting the elements in descending order (highest to lowest). Then write a main program that reads a list of integers from input, stores the integers in a vector, calls SortVector(), and outputs the sorted vector. The first input integer indicates how many numbers are in the list. Ex: If the input is: 5 10 4 39 12 2 the output is: 39,12,10,4,2, For coding simplicity, follow every output value by a comma, including the last one. Your program must define and call the following function:void SortVector(vector<int>& myVec) #include <iostream>#include <vector>using namespace std; /* Define your function here */ int main() { /* Type your code here */ return 0;} Enter program input - 5 10 4 39 12 2arrow_forward
- complete the //TODOs #include<iostream> #include "swap.h" using namespace std; int main(int argc, char const *argv[]) { intfoo[5] = {1, 2, 3, 4, 5}; cout<<"Addresses of elements:"<<endl; //TODO Print the addresses of array elements cout<<endl; cout<<"Elements:"<<endl;; //TODO Print all the elements using pointers cout<<endl; inta,b; intf; intflag = 1; while(flag == 1){ cout<<"Enter indices of elements you want to swap?"<<endl; cout<<"First index"<<endl; cin>>a; cout<<"Second index"<<endl; cin>>b; cout<<"Enter 0 for pass-by-value, 1 for pass-by-pointer"<<endl; cin>>f; switch (f) { case0: // Pass by Value // Compare the resultant array with the array you get after passing by pointer cout<<"Before swapping"<<endl; for(inti = 0;i<5;i++){ cout<<foo[i]<<" "; } cout<<endl; swap(foo[a],foo[b]); cout<<"\nAfter swapping"<<endl;…arrow_forwardC++ programming language.arrow_forwardlanguage = pythonarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





