Question
Finding 2 largest numbers in a list (page 5 of last lecture, more on algorithms) TwoLargest should be written as a function that is called
Finding 2 largest numbers in a list (page 5 of last lecture, more on algorithms) TwoLargest should be written as a function that is called in main. The user should be able to enter any list of numbers that they wish. Hint: You can use parts of the code from the bubblesort example such as vector_get() to create the list of numbers. Additionally, length(A) = n can also be found with A.size() in C++ so TwoLargest can be written with only one argument.
proceedure TwoLargest(A = [a1...an], length(A) = n)
large_1 = 0
large_2 = 0
for i = 1 to n
if A[i] > large_1
large_2 = large+1
large_1 = A[i]
else if large_2 < A[i]
large2 = A[i]
Step 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