changeset 54:f540de861cd6

add Node struct
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Mon, 08 Jun 2015 15:47:52 +0900
parents 82fbc8478f7b
children 883e3473a9f5
files c/regexParser/main.cc
diffstat 1 files changed, 14 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- 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 <stdlib.h>
 #include <string.h>
 
-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;
 }