Richard Walker

Greenhorn
+ Follow
since Feb 20, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Richard Walker

OK. Scratch that attempt - it's not really any improvement. Let's go back to your first listing.

My suggestion is to re-think your implementations of express() and term() so that you don't expect to successfully call term() and primary() more than once. The reason is that if, for example, express() is called with the input buffer containing a term and a minus then the first test, for term and a plus, would fail even though term() was successful and incremented the index. Then next check, for term and a minus, which you would expect to succeed will fail as well. This time because term() now won't match the character at the new index position (because it's now a minus).

Instead of thinking of an expression as three alternatives (either a term followed by a plus or a term followed by a minus or a term on its own) which leads to checking for a term three times, try thinking sequentially: Have I got a term? If not, I haven't got an expression. If so, have I got a plus or a minus? If not, I have got an expression. If so, have I got an expression?... and so on.
15 years ago
The first thing that springs to mind is to use a Map<DATE,Integer> to hold a count for each DATE. For each object in your List<>, get the count for the DATE out of the Map, and put it back an incremented count.
15 years ago
Hi Jon.

As you say, nearly there. The first thing to look at is the multiple calls to term() in express() and primary() in term(). They have a side effect when they are successful (changing the value of index), so they can't be successful more than once at the same index which is what you would need for the else parts of your tests to succeed.

I think you'll also find that you need to take a bit more care with your charAt() indexes when you get to the end of s.
15 years ago
Try R* Trees. Wikipedia does have an entry for those. I guess they're what you're looking for.
15 years ago