How the Algorithms Work
To see how the algorithms can be used on varying types of containers, let’s look a bit more closely at find. Its job is to find a particular element in an unsorted sequence of elements. Conceptually, we can list the steps find must take:
1. It accesses the first element in the sequence.
2. It compares that element to the value we want.
3. If this element matches the one we want, find returns a value that identifies this element.
4. Otherwise, find advances to the next element and repeats steps 2 and 3.
5. find must stop when it has reached the end of the sequence.
6. If find gets to the end of the sequence, it needs to return a value indicating that the element was not found. This value and the one returned from step 3 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access