[top][index]
search for:

maxPosition BasicList -- position of largest element

Synopsis:

  • Usage: n = maxPosition x
  • Function: maxPosition -- position of largest element
  • Input:
  • x, an instance of class BasicList.
  • Output:
  • n, an instance of class ZZ: the position of the largest element in the list x.
  • If the largest element occurs more than once, then the first occurrence is used. If x has length 0 an error results.

    See also:

  • minPosition BasicList -- position of smallest element
  • Code:

         -- ../../../Macaulay2/m2/lists.m2:22-28
         maxPosition BasicList := ZZ => x -> (
              if # x === 0 then error "expected a nonempty list" 
              else (
                   m := x#0; 
                   pos := 0;
                   scan(1 .. # x-1, i -> if x#i>m then (m=x#i;pos=i));
                   pos))

    [top][index]
    search for: