作業說明:
用 fork() 產生一個 process tree, 每個 process 皆印出一行 messages, 其順序
為 post-order. 順序之達成可用 wait() 來達成.
程式讀進一個參數, 表此 binary tree 之 internel path. 如 "101" 表 internel
path 之 length 為 3, 亦即有 4 個 intenel node. root 為第一個, 由其開始,
先向右, 再向左, 再向右 , tree 的形狀如下:
I
/ \\ <--- (1)
E I
(0) ---> // \
I E
/ \\ <-----(1)
E I
/ \
E E
其中 I 表 internel node, E 表 external node, 其中 internel 要印出
I'm ..., my two children is ... and ....
external node 要印出
I'm ..., my parent is ...
底下為程式之 output 及其對應之 tree.
$ ./a.out ""
I'm 1054, my parent is 1053 | 1053
I'm 1055, my parent is 1053 | / \
I'm 1053, my two children is 1054 and 1055 | 1054 1055
$ ./a.out "1" |
I'm 1057, my parent is 1056 | 1056
I'm 1059, my parent is 1058 | / \\
I'm 1060, my parent is 1058 | 1057 1058
I'm 1058, my two children is 1059 and 1060 | / \
I'm 1056, my two children is 1057 and 1058 | 1059 1060
$ ./a.out "10" |
I'm 1062, my parent is 1061 | 1061
I'm 1065, my parent is 1064 | / \\
I'm 1066, my parent is 1064 | 1062 1063
I'm 1064, my two children is 1065 and 1066 | // \
I'm 1067, my parent is 1063 | 1064 1067
I'm 1063, my two children is 1064 and 1067 | / \
I'm 1061, my two children is 1062 and 1063 | 1065 1066
$