# HG changeset patch # User Masataka Kohagura # Date 1433746072 -32400 # Node ID f540de861cd64ebd2a3e7cb0c834d54ad9837130 # Parent 82fbc8478f7ba12ceade659c3e04e0b92c39d337 add Node struct diff -r 82fbc8478f7b -r f540de861cd6 c/regexParser/main.cc --- a/c/regexParser/main.cc Thu Jun 04 18:04:42 2015 +0900 +++ b/c/regexParser/main.cc Mon Jun 08 15:47:52 2015 +0900 @@ -2,58 +2,28 @@ #include #include -int bitBlock = sizeof(unsigned long) * 8; +typedef struct node { + struct node *left; + struct node *right; + int type; + int value; +} Node, *NodePtr; -typedef struct bitInfo { - int arrayNum; - unsigned long *bitContainer; -}BitInfo,*BitInfoPtr; - -void bitSet(BitInfoPtr bi, int bitSetPosition) { - - unsigned long tmp = 1; - int arrayPosition = 0; - arrayPosition = bitSetPosition / bitBlock; - bitSetPosition = bitSetPosition % bitBlock; - - tmp = tmp << (bitBlock - 1 - bitSetPosition); - bi->bitContainer[arrayPosition] = bi->bitContainer[arrayPosition] | tmp; -} - -void bitPrint(BitInfoPtr bi) { - for (int i = 0; i < bi->arrayNum ; i++) { - for (int j = bitBlock - 1; j >= 0; j--) { - printf( "%lu", ( bi->bitContainer[i] >> j ) & 1 ); - } - printf(" "); - } - puts(""); +NodePtr newNode(int type, int value, NodePtr left, NodePtr right) { + NodePtr d = (NodePtr)malloc(sizeof(Node)); + d->type = type; + d->value = value; + d->left = left; + d->right = right; + return d; } int main(int argc, char **argv) { - BitInfoPtr bi = (BitInfoPtr)malloc(sizeof(BitInfo)); - int bitSetPosition = 0; + for (int i = 1; i < argc ; i++) { - for (int i = 1; i < argc ; i++) { - if (strcmp(argv[i],"-n") == 0) { - bitSetPosition = atoi(argv[i+1]); - } } - bi->arrayNum = (bitSetPosition + 1) / bitBlock; - if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; - - printf("Array Num : %d\n",bi->arrayNum); - - unsigned long bitContainer[bi->arrayNum]; - for (int i = 0; i < bi->arrayNum; i++) { - bitContainer[i] = 0; - } - - bi->bitContainer = bitContainer; - bitSet(bi,bitSetPosition); - bitPrint(bi); return 0; }