I'm writing a program for a school assignment, and here's my scenario:
I have a txt file that has words delimited by punctuation marks on various lines, and I need to take in these words, insert them into a Red Black Tree, then produce an outputfile that prints each word in the file, followed by it's line number, and if the word appears more than once, have each subsequent line number printed seperated by commas, so for instance:
java 1, 3, 5
meaning that the word "java" appeared on lines 1, 3 and 5 of the txt file.
Ok, so I can read in the words, insert them into the RedBlack tree just fine, I just can't come up with a method of retrieving the line numbers that each word appears on and somehow storing it in a collection to keep track of it.
I thought about possibly having a Red Black Tree that would store 2 strings per node, the word and a list of line numbers it appeared on but I can't find any source code for a Red Black tree class that allows this function, and I can't figure out how to re-write the RB tree class i have so it does this. This is the class file i'm using:
to make it compile w/o using the package, i commented out the package name at the top and i changed line 72 from:
throw new DuplicateItemException( item.toString( ) );
to simply: return;
I saw another site online that did this, and the class worked fine.
Thanks in advance