Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Binary tree problems

sandratzsandratz Posts: 18Member
How can I store data, print and query an ADT with an interface such as the one below?
Please can someone write me a sample code? (A million thanks to you) I've written my code but it is too long and it does not work well.


[code]
struct pagelist {
struct pagelist *next;
int page;
};

struct node {
char *word;
struct pagelist *head;
struct node *left;
struct node *right;
int size;
};

typedef struct node NODE;
typedef struct node *Index;

void IndexInit(Index *); //initialise an index
void IndexAppend(Index*, char*,int); //appends an entry into the index. It first checks if the word already exists in the words tree, and if it exists, adds the page number into the page number list of that word. However, if the entered page number already exists in the corresponding list, it simply discards the new entry. If the word doesn't exist in the words tree, it appends a new node into the Red-Black tree and appends a node into its (new node's) page number list.
//In short, the data structure does not allow duplicates either in the top-level (words) tree or page numbers lists. Top-level tree is maintained in the alphabetically ordered Red-Black tree of words, and page number lists are maintained in the ascending order of page numbers. Each insertion should adhere these rules.
void IndexPrint(Index *); //displays the entire index, as appeared at the end of a text book, i.e. each indexed word in a separate line, followed by a comma separated ordered list of page numbers. If more than two adjacent page numbers appear in a page list, they should be displayed as a range, i.e. if the term 'Abstract' appear in pages 10, 45, 46, 47 and 48, it should be displayed as;
// Abstract 10, 45 - 48.
int IndexQuery(Index*,char*,int**);reads in an Index ADT instance and a word as the input and returns the list of page numbers on which the word appears. The third argument in the prototype is an array of integers, which is used to return the results set. The function also returns the number of page numbers n the results set as well. (The return value of the function is used for this purpose).
void IndexDestroy(Index *);//destroy the index
[/code]

Sign In or Register to comment.