How to resolve the algorithm Greatest element of a list step by step in the ooRexx programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest element of a list step by step in the ooRexx programming language
Table of Contents
Problem Statement
Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Greatest element of a list step by step in the ooRexx programming language
Source code in the oorexx programming language
-- routine that will work with any ordered collection or sets and bags containing numbers.
::routine listMax
use arg list
items list~makearray -- since we're dealing with different collection types, reduce to an array
if items~isEmpty then return .nil -- return a failure indicator. could also raise an error, if desired
largest = items[1]
-- note, this method does call max one extra time. This could also use the
-- do i = 2 to items~size to avoid this
do item over items
largest = max(item, largest)
end
return largest
/* REXX ***************************************************************
* 30.07.2013 Walter Pachl as for REXX
**********************************************************************/
s=.list~of('Walter','lives','in','Vienna')
say listMax(s)
-- routine that will work with any ordered collection or sets and bags.
::routine listMax
use arg list
items=list~makearray -- since we're dealing with different collection types, reduce to an array
if items~isEmpty then return .nil -- return a failure indicator. could also raise an error, if desired
largest = items[1]
-- note, this method uses one extra comparison. It could use
-- do i = 2 to items~size to avoid this
do item over items
If item>>largest Then
largest = item
end
return largest
You may also check:How to resolve the algorithm Assertions step by step in the D programming language
You may also check:How to resolve the algorithm Bin given limits step by step in the Tcl programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the Ruby programming language
You may also check:How to resolve the algorithm Substring step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Ranking methods step by step in the Julia programming language