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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 07:00, ayoismeisalex
Our primary purpouse as electricians is to do wich of the following core concepts? a: install electrical components in a way they can be upgraded b: install electrical equiptment in a way that reduces heat c: install electrical systems in a safe manner d: only b and c
Answers: 1
image
Computers and Technology, 22.06.2019 22:10, Metlife
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, bre563
Research data that is presented using descriptive language is said to be
Answers: 2
image
Computers and Technology, 23.06.2019 12:00, anamatiascamaja
If you embed a word table into powerpoint, what happens when you make edits to the embedded data? a. edits made to embedded data change the data in the source file; however, edits made to the source file will not be reflected in the embedded data. b. edits made to embedded data will change the data in the source file, and edits made to the source file will be reflected in the embedded data. c. edits made to embedded data don't change the data in the source file, nor will edits made to the source file be reflected in the embedded data. d. edits made to embedded data don't change the data in the source file; however, edits made to the source file will be reflected in the embedded data.
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 in other subjects:

Konu
History, 12.04.2021 18:00
Konu
Arts, 12.04.2021 18:00
Konu
Mathematics, 12.04.2021 18:00
Konu
Physics, 12.04.2021 18:00