Devise an algorithm that takes a list of n > 1 integers and finds the largest and smallest values in the list.
In algorithm, we have implemented the Bubble Sort algorithm that will sort the list element in an ascending order. The First element of the list will always be smallest element and the last element of the list will always be largest element of the list. Please rate our program as Helpful. Let us know if there is any further query. Thanks.
Explanation:
Solution:
Algorithm_1(DATA, N)
(a) if DATA[PTR] > DATA[PTR + 1] then:
i. Set temp := DATA[PTR]
ii. Set DATA[PTR] := DATA[PTR +1]
iii. Set DATA[PTR + 1] := temp
[End of If Structure]
(b) Set PTR := PTR +1
[End of Inner Loop]
[End of Step Outer 3 Loop]
6. Set Smallest := DATA[0]
7. Set Largest := DATA[N-1]
8. Exit.
Get Answers For Free
Most questions answered within 1 hours.