ArrayLinearList
a linear list is represented in a one-dimensional array
element. The data member size
is such that the list elements are in positions 0
through size-1 of the array.
The member method rightShift shifts the
elements of the linear list right by k
positions and fills the empty positions at the left end
with null.
For example, if the list element[0:5]
= [1, 2, 3, 4, 5, 6], whose size is 6, is shifted right by 3, the result is
[0, 0, 0, 1, 2, 3, 4, 5, 6], whose size is 9.
rightShift
member method.
Chain which has the
data members firstNode and size.
The data type of
firstNode is ChainNode.
Objects of type ChainNode have the data members
element and next.
Nodes on a chain are linked together using the field next.
isSorted, which is a member
of Chain determines whether
the chain elements are in ascending (more accurately nondecreasing)
order of their element values.
The method returns true
if the chain is sorted and false
if it is not.
isSorted
member method.
To compare two objects a and
b you may do something like
if (((Comparable) a).compareTo(b) > 0)
{// come here only if a greater than b
}
x x
x x x
x x zero x
x x x
x x x
x zero x x
x x x
x x
x denotes a possible nonzero
all other terms are zero
NMatrix
that represents an n x n
N-matrix in a one-dimensional array element as above.
Besides element, the class has the data
members n and zero (the
zero element for the matrix).
Write Java code for the member method set(i, j, newValue) which
stores newValue as the (i,j)
element
of the N-matrix, 1 <= i <= n
and
1 <= j <= n.
The element is to be stored in the proper position of the one-dimensional
array element.