Mercurial > hg > Members > masakoha > testcode
changeset 69:eecddded9b91
implement printTree
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 12 Aug 2015 15:10:50 +0900 |
parents | d27b3af1fe75 |
children | 87dff3a124ab |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Tue Aug 11 19:46:33 2015 +0900 +++ b/c/regexParser/main.cc Wed Aug 12 15:10:50 2015 +0900 @@ -203,21 +203,23 @@ * a */ -void descendTree(NodePtr n,int d) { +void descendTree(NodePtr n) { + static int d = 0; if (n->right != NULL) { d++; - descendTree(n->right, d); - } else if (n->left != NULL) { + descendTree(n->right); + d--; + } + printf("%*c%c\n",d*4, ' ',n->Value.character); + if (n->left != NULL) { d++; - descendTree(n->right, d); - } else { - printf("%c\n",n->Value.character); + descendTree(n->left); + d--; } } void printTree(NodePtr n) { - int depth = 0; - descendTree(n,depth); + descendTree(n); }