Java Reference
In-Depth Information
Here, length helps perform two important functions. First, it is used to confirm that the tar-
get array is large enough to hold the contents of the source array. Second, it provides the
termination condition of the for loop that performs the copy. Of course, in this simple ex-
ample, the sizes of the arrays are easily known, but this same approach can be applied to a
wide range of more challenging situations.
Try This 5-2 A Queue Class
As you may know, a data structure is a means of organizing data. The simplest data struc-
ture is the array, which is a linear list that supports random access to its elements. Arrays
are often used as the underpinning for more sophisticated data structures, such as stacks
and queues. A stack is a list in which elements can be accessed in first-in, last-out (FILO)
order only. A queue is a list in which elements can be accessed in first-in, first-out (FIFO)
order only. Thus, a stack is like a stack of plates on a table—the first down is the last to be
used. A queue is like a line at a bank—the first in line is the first served.
Search WWH ::




Custom Search