How to find elements

There are two methods for searching for data in an array. Sequentially and binary chop.

A search can be made for elements based on the value of a key. A search can be done in one of two ways:

  • Sequentially through the array, starting with the first element — performed using the Find() member function

  • Using a binary search (binary chop) technique — performed using the FindIsq() member function. This technique assumes that the array elements are in key sequence.

Both functions indicate the success or failure of the search and, if successful, supply the position of the element within the array.

Note that where an array has elements with duplicate keys:

  • Find() only supplies the position of the first element in the array with that key.

  • FindIsq() cannot guarantee which element, with the given key value, it will return; except that it will find one of them.

The elements of arrays can be sorted. This is done by the Sort() member function for CArrayFixFlat<class T>, CArrayFixSeg<class T>, CArrayVarFlat<class T> and CArrayVarSeg<class T> arrays. You must use the SortL() member function for the CArrayPakFlat<class T> array.