Question: Ex 1 . Morale Boosters 3 5 points Overview The goal of this exercise is to make sure that you have mastered the basics of

Ex1. Morale Boosters
35 points
Overview
The goal of this exercise is to make sure that you have mastered the basics of using sets, maps, and vectors, before moving to the other exercises.
Task # 1
Implement function void read_and_reverse()(in file vector_rev.cpp) which keeps reading non-negative integers from the user until the user enters a negative integer. When a negative integer is entered, the function prints the entered integers (separated by spaces) in reverse order.
For example, if the user enters 2035-1, the function prints 5302.
Note. You must use the STL vector.
Running Time.
(
)
O(n) where
n is the size of the vector.
Task # 2
Implement function void reverse_stack(stack& s)(in file stack_rev.cpp), which reverses the contents of the received stack.
Note. You must use the STL queue.
Running Time.
(
)
O(n) where
n is the size of the stack.
Task # 3
Implement function void dedup(vector& v)(in file dedup.cpp), which removes duplicate elements from the received vector. For example, if v ={1,3,2,1,919799293,2,2,5,1}, then calling dedup(v) makes the contents: {1,3,2,919799293,5}. Note that the first occurrence of the repeated elements is not removed and that the original order of the elements is maintained.
Note. You must use the STL set.
Running Time.
(
log
)
O(nlogn) where
n is the size of the vector.
Task # 4
Implement function string most_frequent(int n)(in file most_freq.cpp), which reads n>0 strings from the user and prints the string that repeated the highest number of times. If there is more than one string that repeats the highest number of times, then the function prints the first of them in lexicographic order.
Example
Input = ibrahim aboud ahmad manaf aboud ahmad ibrahim ahmad aboud
Output = aboud
Explanation:
string frequency
ibrahim 2
aboud 3
ahmad 3
manaf 1
The most repeated strings are "aboud" and "ahmad".
Since "aboud" is lexicographically before "ahmad", the function prints "aboud".
Note. You must use the STL map.
Running Time.
(
log
)
O(nlogn).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!