comparison c/regexParser/printTree.cc @ 90:d139af3bbd67

remove static variable in printTree.cc
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 23 Oct 2015 17:48:01 +0900
parents 50a146c05192
children 912d7bd51f38
comparison
equal deleted inserted replaced
89:50a146c05192 90:d139af3bbd67
1 #include <stdio.h> 1 #include <stdio.h>
2 #include "regexParser.h" 2 #include "regexParser.h"
3 3
4 void descendTree(NodePtr n) { 4 void descendTree(NodePtr n, int d) {
5 static int d = 0;
6 if (n->right != NULL) { 5 if (n->right != NULL) {
7 d++; 6 d++;
8 descendTree(n->right); 7 descendTree(n->right, d);
9 d--; 8 d--;
10 } 9 }
11 if (n->tokenType == 'a') { 10 if (n->tokenType == 'a') {
12 printf("%*c(%d)%c\n",d*4, ' ',n->nodeNumber,n->Value.character); 11 printf("%*c(%d)%c\n",d*4, ' ',n->nodeNumber,n->Value.character);
13 } else { 12 } else {
14 printf("%*c%c\n",d*4, ' ',n->Value.character); 13 printf("%*c%c\n",d*4, ' ',n->Value.character);
15 } 14 }
16 15
17 if (n->left != NULL) { 16 if (n->left != NULL) {
18 d++; 17 d++;
19 descendTree(n->left); 18 descendTree(n->left, d);
20 d--; 19 d--;
21 } 20 }
22 } 21 }
23 22
24 void printTree(NodePtr n) { 23 void printTree(NodePtr n) {
25 puts("---Print Node----"); 24 puts("---Print Node----");
26 descendTree(n); 25 int d = 0;
26 descendTree(n,d);
27 puts("-----------------"); 27 puts("-----------------");
28 } 28 }