...
(Note: there are more efficient ways of writing this method, but I wanted to show you several features at once)
A vararg parameter comes in as an array, so one can figure out how many parameters were supplied (params.length) and one can access each supplied value using regular array syntax, e.g. params\[i\].
\\ Wiki Markup
The following are all valid calls to the above method:
...
Consider the following sorted array of values:unmigrated-wiki-markup
{{\[1,
2,
4,
7,
10,
11,
12,
13,
20,
25,
27,
28,
30
\]
}}
Supposed you're give a value, x
, what's the fastest way to either find that value in the array or determine if it is not present?
...
One way to look at what is going on here is to think of the sorted array as already being in the form of a binary search tree, where each mid-point is the top node of a sub-tree. All the above algorithm is doing is walking down from the top of the binary search tree., i.e the path 12 => 7 => 10 => 11.
No Format |
---|
12
/ \
7 25
/ \ / \
2 10 13 28
/ \ \ \ / \
1 4 11 20 27 30
|
It is a very useful notion to conceptually view an array as a tree. This enables one to leverage the power of recursive data structures with the speed and compactness of an array.
====================================================================================================================
...
Inserting a node into a doubly-linked list, ala BiList
, isn't difficult, but it does take care to make sure that one has the right values for the node references at any given moment. Here's a pictoral explanation of the process: