FreeBSD6.0Release下查看带宽使用情况的几个命令 转]
2008-03-09 09:44
351 查看
Let us consider the below traversals:
Inorder sequence: D B E A F C
Preorder sequence: A B D E C F
In a Preorder sequence, leftmost element is the root of the tree. So we know ‘A’ is root for given sequences. By searching ‘A’ in Inorder sequence, we can find out all elements on left side of ‘A’ are in left subtree and elements on right are in right subtree. So we know below structure now.
We recursively follow above steps and get the following tree.
Algorithm: buildTree()
1) Pick an element from Preorder. Increment a Preorder Index Variable (preIndex in below code) to pick next element in next recursive call.
2) Create a new tree node tNode with the data as picked element.
3) Find the picked element’s index in Inorder. Let the index be inIndex.
4) Call buildTree for elements before inIndex and make the built tree as left subtree of tNode.
5) Call buildTree for elements after inIndex and make the built tree as right subtree of tNode.
6) return tNode.
Inorder sequence: D B E A F C
Preorder sequence: A B D E C F
In a Preorder sequence, leftmost element is the root of the tree. So we know ‘A’ is root for given sequences. By searching ‘A’ in Inorder sequence, we can find out all elements on left side of ‘A’ are in left subtree and elements on right are in right subtree. So we know below structure now.
A / \ / \ D B E F C
We recursively follow above steps and get the following tree.
A / \ / \ B C / \ / / \ / D E F
Algorithm: buildTree()
1) Pick an element from Preorder. Increment a Preorder Index Variable (preIndex in below code) to pick next element in next recursive call.
2) Create a new tree node tNode with the data as picked element.
3) Find the picked element’s index in Inorder. Let the index be inIndex.
4) Call buildTree for elements before inIndex and make the built tree as left subtree of tNode.
5) Call buildTree for elements after inIndex and make the built tree as right subtree of tNode.
6) return tNode.
TreeNode buildTree(char in[], char pre[], int inStr, int inEnd){ int preIndex = 0; if(inStr > inEnd) return null; TreeNode tNode = new TreeNode(pre[preIndex++]); if(inStr == inEnd) return tNode; int inIndex = search(in, inStr, inEnd, tNode.item); tNode.left = buildTree(in, pre, inStr, inIndex - 1); tNode.right = buildTree(in, pre, inIndex + 1, inEnd); return tNode; } int search(char arr[], int strt, int end, char value){ int i; for(i = strt; i <= end; i++){ if(arr[i] == value) break; } return i; }
相关文章推荐
- FreeBSD6.0Release下查看带宽使用情况的几个命令[转]
- Nethogs 命令使用--网络带宽占用情况查看工具
- linux网络命令及工具(修改链接速度、双工、查看带宽使用情况)
- linux下查看系统内存使用情况的几个命令
- Linux使用jstat命令查看jvm的GC情况
- DOS命令查看端口使用情况
- Linux 使用jstat命令查看jvm的GC情况
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- iostat命令查看磁盘使用情况
- 查看linux服务器内存使用情况free -m命令详解
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- windows自带命令和工具查看端口使用情况
- 在Linux下使用命令查看系统中RAID的情况
- linux查看cup使用情况 sar命令
- mac查看内存使用情况命令
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- 关于查看文件使用情况的命令
- Linux使用jstat命令查看jvm的GC情况
- linux 查看cpu使用情况 (top)命令
- 查看数据库的端口使用情况命令