This has the same problem as the original code. :) Try zhao's example.
On Fri, Jun 11, 2010 at 7:23 PM, Ted Dunning <[email protected]> wrote: > Iterator<Element> myIter = iterateNonZero(); > Iterator<Element> otherIter = x.iterateNonZero(); > double result = 0.0; > if (myIter.hasNext() && otherIter.hasNext()) { > Element myCurrent = myIter.next(); > Element otherCurrent = otherIter.next(); > while (myIter.hasNext() && otherIter.hasNext()) { > int myIndex = myCurrent.index(); > int otherIndex = otherCurrent.index(); > if (myIndex == otherIndex) { > result += myCurrent.get() * otherCurrent.get(); > } > if (myIndex <= otherIndex) { > myCurrent = myIter.next(); > } > if (myIndex >= otherIndex) { > otherCurrent = otherIter.next(); > } > } > } > return result; >
