> Using a binary search tree for making an index?

Using a binary search tree for making an index?

Posted at: 2014-12-18 
I am trying to use a binary search tree in order to make a book index out of a given file. The strings in the file are formatted specifically in order to incorporate the page numbers, sub-levels of a given index, etc. Here is an example of a text file:

IX: {Series|(} {2}

IX: {Series!geometric|(} {4}

IX: {Euler’s constant} {4}

IX: {Series!geometric|)} {4}

IX: {Series!arithmetic|(} {4}

IX: {Series!arithmetic|)} {5}

IX: {Series!harmonic|(} {5}

IX: {Euler’s constant} {5}

IX: {Series!harmonic|)} {5}

IX: {Series|)} {5}

The above lines should produce in other text file:

Euler’s constant: 4,5

Series: 2-5

arithmetic: 4-5

geometric: 4

harmonic: 5

"|(" characters at the beginning of a string represent the start of a range, ")|" means end of a range, and "!" means subindex.

We have to use a binary search tree to accomplish this task, and I have written my Binary Search Tree class, but I have no idea how to go about writing the code for this task. Could someone guide me in the right direction as to how I should be thinking about using a tree for this task? So far, all I can do is parse the file in order to get out whatever is in the middle of the curly brackets and save those to a list. Thanks in advance.