Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In my current tasks in my lab course I am required to create the following algorithms in C++ using Pre-sorting. The text file in question
In my current tasks in my lab course I am required to create the following algorithms in C++ using Pre-sorting. The text file in question would be formatted like this: "
41 85 72 38 80 69 65 ....etc. "
I would appreciate comments to be written on the code so as to be able to understand how the result was achieved. Thank you in advance.
Task 1 [task_1.cpp] 1. [3 points] Write the function void get_frequencies (double arr[], int n) where Input: An n-element array of doubles & its size n Output: Print the frequency (number of repetitions) of each element in the array in 0 (n lg n) time Hint: Use pre-sorting 2. [2 points] In main, test out the function and make sure your output looks like SO Array: 4 22 Element Frequency 9 Task 2 [task_2.cpp] 1. [3 Points] Write the function double most_frequent(double arr[], int n) where Input: An n-element array of doubles and its size, n Output: Returns the most repeated element in the array in O(nlg n) time. Hint: Use pre-sorting 2. [2 Points] In main, test your function by reading the numbers in the file numbers.txt (posted on Blackboard) and display the most frequent element among them. Also, print their frequencies using get_frequencies. 10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started