perform a binary placement in a list - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : ListTools Package : ListTools/BinaryPlace

ListTools[BinaryPlace] - perform a binary placement in a list

Calling Sequence

BinaryPlace(L, x, f, opt1, opt2, ...)

Parameters

L

-

list, Vector, or one-dimensional Array

x

-

anything

f

-

(optional) procedure, operator, or algebraic expression

opt1, opt2, ...

-

(optional) extra arguments to f

Description

• 

The BinaryPlace(L, x) function performs a binary placement of x in L, where L is assumed to be sorted.  It returns the greatest index n such that L[n] precedes x. If x precedes all elements in a list L, then the value 0 is returned.

  

In this form of the calling sequence, x must be of type numeric or string and L should contain values of the same type in ascending order.

• 

BinaryPlace also accepts a Vector or one-dimensional Array as its first argument. If x precedes all elements in an Array, then the value that is returned is the lowerbound of the Array minus one. Since Vectors, like lists, always have a lowerbound of 1, the value returned for a Vector in this case is 0.

• 

If L is a list, then the returned value n is such that op1..n,L,x,opn+1..1,L is still a sorted list. If L is a Vector or Array, then the returned value n is such that opconvertL..n,list,x,opconvertLn+1..,list is sorted.

• 

If three or more arguments are specified in the calling sequence, then fx,y,opt1,opt2,... must return true if x precedes y.

Examples

withListTools:

L:=1,5,7,8,10:

n:=BinaryPlaceL,6

n:=2

(1)

op1..n,L,6,opn+1..1,L

1,5,6,7,8,10

(2)

BinaryPlacemac,made,magpie,mail,magic

2

(3)

BinaryPlace0,sin12,1,ⅇ110,verify,less_than

2

(4)

BinaryPlace4,1,2,4,1,2,3,4,2,4,`subset`

1

(5)

An example with a reverse-sorted Array. Note that the eight elements of this Array are indexed with the numbers 2 up to 5.

A:=Array2..5,173,157,101,21,17,3,33,62

A:=Array2..5,2=173,1=157,0=101,1=21,2=17,3=3,4=33,5=62

(6)

By supplying `>` for f, we get BinaryPlace to understand the reverse ordering.

BinaryPlaceA,0,`>`

2

(7)

We find that the elements 2 up to 2 are the positive ones, 3 up to 5 are negative.

convertA..2,'list'

173,157,101,21,17

(8)

convertA3..,'list'

3,33,62

(9)

See Also

list, ListTools, ListTools[BinarySearch], sort, type/list, type/numeric, type/string


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam