subject

Write a program in C++ that creates three identical arrays, list1, list2, and list3 of 5000 elements. The program then sorts list1 using bubble sort, list2 using selection sort, and list3 using insertion sort and outputs the number of comparisons and item assignments made by each sorting algorithm. functions. cpp
#include
#include
#include
using namespace std;
inline void fillArray(int list[], int length)
{
srand(time(0));

for (int i = 0; i < length; i++)
list[i] = rand() % 20000;
}
inline void copyArray(int list1[], int list2[], int length)
{
for (int i = 0; i < length; i++)
list2[i] = list1[i];
}
inline void bubbleSort(int list[], int length, int& comp, int& assign)
{
// write a function using bubble sort to sort the provided array
// assign "comp" to the number of comparisons required
// assign "assign" to the number of item assignments
}
inline void selectionSort(int list[], int length, int& comp, int& assign)
{
// write a function using selection sort to sort the provided array
// assign "comp" to the number of comparisons required
// assign "assign" to the number of item assignments
}
inline void insertionSort(int list[], int listLength, int& comp, int& assign)
{
// write a function using insertion sort to sort the provided array
// assign "comp" to the number of comparisons required
// assign "assign" to the number of item assignments
}
main. cpp
#include
#include
#include
#include "functions. cpp"
using namespace std;
int main()
{
int list1[5000];
int list2[5000];
int list3[5000];
int compBubbleSort = 0, compSelectionSort = 0, compInsertionSort = 0;
int assignBubbleSort = 0, assignSelectionSort = 0, assignInsertionSort = 0;
fillArray(list1, 5000);
copyArray(list1, list2, 5000);
copyArray(list1, list3, 5000);
bubbleSort(list1, 5000, compBubbleSort, assignBubbleSort);
selectionSort(list2, 5000, compSelectionSort, assignSelectionSort);
insertionSort(list3, 5000, compInsertionSort, assignInsertionSort);
cout << "Number of comparisons---" << endl;
cout << " Bubble sort: " << compBubbleSort << endl;
cout << " Selection sort: " << compSelectionSort << endl;
cout << " Insertion sort: " << compInsertionSort << endl << endl;
cout << "Number of item assignments---" << endl;
cout << " Bubble sort: " << assignBubbleSort << endl;
cout << " Selection sort: " << assignSelectionSort << endl;
cout << " Insertion sort: " << assignInsertionSort << endl << endl;
return 0;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:20
Write a javascript program that reads three integers named start, end, and divisor from three text fields. your program must output to a div all the integers between start and end, inclusive, that are evenly divisible by divisor. the output integers must be separated by spaces. for example, if a user entered 17, 30, and 5, your program would output "20 25 30" (without the quotes) because those are the only integers between 17 and 30 (including 17 and 30) that are evenly divisible by 5.
Answers: 2
question
Computers and Technology, 23.06.2019 01:20
Me with this program in c++ ! computers represent color by combining sub-colors red, green, and blue (rgb). each sub-color's value can range from 0 to 255. thus (255, 0, 0) is bright red. (130, 0, 130) is a medium purple. (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (in other word, equal amounts of red, green, blue yield gray).given values for red, green, and blue, remove the gray part. ex: if the input is 130 50 130, the output is: 80 0 80. thus, find the smallest value, and then subtract it from all three values, thus removing the gray.
Answers: 3
question
Computers and Technology, 23.06.2019 07:50
Most shops require the technician to enter a starting and ending time on the repair order to track the actual time the vehicle was in the shop and closed out by the office. this time is referred to as _ time ? a. comeback b. ro c. cycle d. lead
Answers: 1
question
Computers and Technology, 23.06.2019 15:10
What role did women fill during world war ii?
Answers: 1
You know the right answer?
Write a program in C++ that creates three identical arrays, list1, list2, and list3 of 5000 elements...
Questions
question
Mathematics, 03.11.2020 08:30
question
Geography, 03.11.2020 08:30
question
Mathematics, 03.11.2020 08:30
Questions on the website: 13722362