How to resolve the algorithm Greatest element of a list step by step in the PureBasic 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 PureBasic 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 PureBasic programming language

Source code in the purebasic programming language

Procedure.f Max (Array a.f(1))
   Protected last, i, ret.f

   ret = a(0)   
   last = ArraySize(a())
   For i = 1 To last
      If ret < a(i)
         ret = a(i)
      EndIf
   Next
   
   ProcedureReturn ret
EndProcedure

Procedure.f maxelement(List tl.f())
  ForEach tl() : mx.f=mx*Bool(mx>=tl())+tl()*Bool(mx<tl()) : Next
  ProcedureReturn mx
EndProcedure

NewList testlist.f() : OpenConsole()
For i=0 To 99 : AddElement(testlist()) : testlist()=Sqr(Random(1000)) : Next
Print("Greatest element = "+StrF(maxelement(testlist()),8)) : Input()

  

You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Factor programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the C programming language
You may also check:How to resolve the algorithm Biorhythms step by step in the R programming language
You may also check:How to resolve the algorithm String prepend step by step in the Erlang programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the Stata programming language