struct Object {
// THESE FIELDS ARE ALREADY DEFINED; YOU MAY NOT MODIFY THEM
Object* next_ptr; // Next object in list; NULL if end oflist.
unsigned int ID; // unique identifier for this object.
unsigned int parent_ID; // 0, if object is root of tree.
// THESE FIELDS REPRESENT THE TREE WHICH NEED TO BE FILLED
Object* parent_ptr; // Initialized as NULL.
unsigned int child_count; // Initialized as 0.
Object** child_ptr_array; // Initialized as NULL.
} ;
Need to implement the method:
Object* convert_List_To_Tree (Object* list_head);
This returns the pointer to the root node
First time, scan the linked list to build a hashtable, where the key is object’s id, the value is address of object, second time, scan the linked list, based on parent id, we look up the address of parent object, update current object’s parent_ptr, and parent object’s child_count and child_ptr_array…
No comments:
Post a Comment