← 返回 doordash 的题目列表Menu Tree Structure with Add, Delete, and Update Operations
类型:online_judge
doordash
Design a menu tree structure that supports operations. Implement the following functionalities:
add_node(parent, value): Add a child node with value under the specified parent node.
delete_node(node): Delete the specified node and all its child nodes.
change_value(node, new_value): Change the specified node's value to new_value.
Example Test Cases
Test Case 1
Input:
add_node(root, 1)
add_node(1, 2)
change_value(2, 3)
delete_node(1)
Output:
Added node with value 1 under parent root
Added node with value 2 under parent 1
Changed node 2 value to 3
Deleted node 1 and its children
Example
Input
add_node(root, 1)
add_node(1, 2)
change_value(2, 3)
delete_node(1)