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, 22.06.2019 18:30
Which of these options are the correct sequence of actions for content to be copied and pasted? select content, click the copy button, click the paste button, and move the insertion point to where the content needs to be inserted. click the copy button, select the content, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, click the copy button, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, move the insertion point to where the content needs to be inserted, click the copy button, and click the paste button.
Answers: 3
question
Computers and Technology, 22.06.2019 19:10
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
Suppose you have 9 coins and one of them is heavier than others. other 8 coins weight equally. you are also given a balance. develop and algorithm to determine the heavy coin using only two measurements with the of the balance. clearly write your algorithm in the form of a pseudocode using the similar notation that we have used in the class to represent sorting algorithms
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
You wanted to look up information about alzheimer's, but you were unsure if it was spelled "alsheimer's" or "alzheimer's." which advanced search strategy would be useful? a) a boolean search b) using a wild card in your search c) trying different search engines d) doing a search for "alsheimer's not alzheimer's" asap. ill give brainlist.
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, 13.03.2020 01:19
question
Mathematics, 13.03.2020 01:20
Questions on the website: 13722363