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:30
Which number on the image above correctly indicates the name of a folder in this url? a.1b.2c.3d.4
Answers: 2
question
Computers and Technology, 23.06.2019 08:30
All of these are true about using adhesive except: a. dissimilar materials can be joined. b. mixing tips are product and material specific. c. a specific application gun may be required. d. two-part adhesives are dispensed using two mixing tips
Answers: 3
question
Computers and Technology, 24.06.2019 07:00
Why would a business likely use a java applet - to back up their data files for the business - to create a program that a customer can launch in their web browser - to create music on a powerpoint presentation - to organize files on their company directory
Answers: 3
question
Computers and Technology, 24.06.2019 14:00
Text or graphics that print at the bottom of every page are called footings footers headers headings
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
English, 03.01.2021 21:50
question
Mathematics, 03.01.2021 21:50
question
Mathematics, 03.01.2021 21:50
question
Mathematics, 03.01.2021 21:50
question
Mathematics, 03.01.2021 21:50
Questions on the website: 13722367