Files
2026-03-27 10:30:51 +08:00

1.0 KiB
Raw Permalink Blame History

对一棵初始为空的二叉查找树Binary Search Tree, BST进行若干插入或删除操作请输出最后的二叉查找树。

bst.png

输入格式: 输入第一行为一个整数 T表示操作数目。随后 T 行每行为Insert K表示插入关键词为K的结点若树中已有关键词为K的结点则不插入或Remove K表示删除关键词为K的结点若树中无关键词为K的结点则不删除其中K为整数。 T 不超过2×10 5 树高不超过10 4 。

输出格式: 输出经上述操作后得到的二叉查找树的中根序列和先根序列,序列中每个整数后一个空格,两个序列之间用空行间隔。

输入样例: 16 Insert 17 Insert 31 Insert 13 Insert 11 Insert 20 Insert 35 Insert 25 Insert 8 Insert 4 Insert 11 Insert 24 Insert 40 Insert 27 Insert 9 Remove 17 Remove 13

输出样例: 4 8 9 11 20 24 25 27 31 35 40

20 11 8 4 9 31 25 24 27 35 40

Code Size Limit 16 KB Time Limit 500 ms Memory Limit 64 MB Stack size limit 8192 KB