Question: C++ program: Searching and sorting Algorithms. Read in the array from the data file of numbers (see below). 1. Find the index of first instance
C++ program: Searching and sorting Algorithms. Read in the array from the data file of numbers (see below).
1. Find the index of first instance of the number 976 using a linear search, this should be in a function outside the main function.
2. Sort the original array using bubble-sort; keep tract of the number of swaps for display at the end of the program.
3. Program a linear search on the bubble-sorted array, to find the first index of the number 976, keep tract of the index and the number of comparisons it makes to find the index for display at the end of the program.
4. Sort the original array using selection-sort; keep tract of the number of swaps for display at the end of the program.
5. Program a binary search on the array that was sorted using selection sort, to find the first index of the number 976. Keep tract of the number of comparisons it makes to display at the end of the program.
6. These steps should be modularized into 2 or more functions. Consider how you might use by value or by reference parameters to return the information needed from your functions.
7. Display your output noting the following:
The index of the first instance of 976 in the original array unsorted.
The number of swaps it takes to bubble-sort the array, and the number of comparisons it takes to find the number 976 in the bubble sorted array using a linear search.
The number of swaps it takes to selection-sort the array and the number of comparisons it takes to find the number 976 in the selection-sorted array using a binary search.
This output should be modularized into its own function.
Data file
10 3440 456 456 456 23 45 789 654 12 345 55 776 567 56 678 543 234 54 90 987 678 543 123 43 678 543 23 567 4 678 56 43 98 976 78 912 999 33 445 667 71 923 453 678 56 21 3 678 56 433 4992 9944 288 388 411 2954 385 398 5843 545 599
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
