This exercise has two purposes: to strengthen your "data structures with pointers" skills and your debugging skills. You will implement a linked list version of the mathematical object called a "vector" and implement the inner-product (or dot-product). This is a trivial computation if vectors are implemented as arrays but becomes interesting when vectors are implemented as linked lists.
To start with, let's review vectors:
double innerProduct = 0;
for (int i=0; i<v.length; i++) {
innerProduct = innerProduct + (vector1[i] * vector2[i]);
}
(0, 0, 0, 0, 0, 5.23, 0, 0, 0, 33.1, 0, 0, 0, 0, 0, 0, -0.9, 0, 0, 0)
[ (5, 5,23) (9, 33.1) (16, -0.9) ]
This says that the first non-zero value 5.23 occurs at position 5,
then the next non-zero value 33.1 occurs at position
9 and so on.
Details:
// To create a vector of 8 elements:
LinkedVector V = RandomVector.makeRandomVector (8);
This method will call your addValue method to add
elements to a LinkedVector instance.
Submission: