Beispiel #1
0
int main(int argc, const char * argv[]) {
    TreeNode *root1 = TreeCreate(2,1,2);
//    IntVector2DPrint(pathSum(root1, 1));
    TreeNode *root2 = TreeCreate(13, 5,4,8,11,INT_MAX,13,4,7,2,INT_MAX,INT_MAX,5,1);
    TreePrint(root2);
    IntVector2DPrint(pathSum(root2, 22));
    return 0;
}
Beispiel #2
0
int main(int argc, const char * argv[]) {
    TreeNode *root1 = TreeCreate(2,1,2);
    std::cout << hasPathSum(root1, 1) << std::endl;
    
    TreeNode *root2 = TreeCreate(15,5,4,8,11,INT_MAX,13,4,7,2,INT_MAX,INT_MAX,INT_MAX,INT_MAX,INT_MAX,1);
    std::cout << hasPathSum(root2, 22) << std::endl;
    return 0;
}
Beispiel #3
0
int main ()
{
    // —оздание дерева с меткой корн¤ СAТ
    Tree * pTree = TreeCreate( "1st" );

    // ƒобавл¤ем дочерние узлы к корню
    TreeNode * pNodeB = TreeInsertChild( pTree->m_pRoot, "2nd" );
    TreeNode * pNodeC = TreeInsertChild( pTree->m_pRoot, "3rd" );
    TreeInsertChild( pTree->m_pRoot, "4th" );

    // ƒобавл¤ем дочерние узлы к узлу СBТ
    TreeInsertChild( pNodeB, "5th" );
    TreeInsertChild( pNodeB, "6th" );

    // ƒобавл¤ем дочерние узлы к узлу СCТ
    TreeInsertChild( pNodeC, "7th" );

    // ќбход дерева 3 способами с распечаткой значений:

    // 1) ѕр¤мой
    TreeDirectWalk( * pTree, & PrintNodeLabel ); 
    std::cout << std::endl;

    // 2) ќбратный
    TreeReverseWalk( * pTree, & PrintNodeLabel ); 
    std::cout << std::endl;

    // 3) —имметричный
    TreeSymmetricWalk( * pTree, & PrintNodeLabel ); 
    std::cout << std::endl;

    // ”ничтожение дерева
    TreeDestroy( pTree );
}
Beispiel #4
0
/**
 * This function initializes the Morse code decoder. This is primarily the generation of the
 * Morse tree: a binary tree consisting of all of the ASCII alphanumeric characters arranged
 * according to the DOTs and DASHes that represent each character. Traversal of the tree is done by
 * taking the left-child if it is a dot and the right-child if it is a dash. If the morse tree is
 * successfully generated, SUCCESS is returned, otherwise STANDARD_ERROR is returned. This function
 * also initializes the Buttons library so that MorseCheckEvents() can work properly.
 * @return Either SUCCESS if the decoding tree was successfully created or STANDARD_ERROR if not.
 */
int MorseInit(void) {
    Header = TreeCreate(6, (&myChar[0]));
    //Create a tree and save the head
    if (Header == NULL) {
        return STANDARD_ERROR;
        //If there is no more space in heap, we need to return a Standard error
    } else {
        //If we alloc successfully, we do the next step
        myState = WAITING;
        myCount = 0;
        return SUCCESS;
    }
}
Beispiel #5
0
int main(int argc, char **argv)
{
    //freopen("in.txt", "r", stdin);
    char szBuffer[16];
    int res = 0;
    
    TreeCreate();
    while (1)
    {
        gets(szBuffer);
        if (strlen(szBuffer) == 0) break;
        TreeInsert(szBuffer);
    }
    while (EOF != scanf("%s", szBuffer))
    {
        res = TreeQuery(szBuffer);
        printf("%d\n", res);
    }
    
    TreeDelete(root);
    
    return 0;
}
Beispiel #6
0
int main(int argc, char **argv)
{
  char *nn_file;
  FILE *fp;
  int **samples, **s1, **s2;
  int i,j,k,c;
  int num_samples;
  int nclusters;
  Partition p;
  int min_dist_thres, max_dist_thres;
  Tree *trees, tree;

  if(argc < 6) {
    printf("Usage:\n%s <nn_file> <num_samples> <shared_thres> <start_dist_thres> <end_dist_thres>\n",
	   argv[0]);
    printf("To generate a hierarchy from <num_samples> lines of the neighbor file <nn_file>.\n");
    printf("dist_thres = distance threshold (k-nearest)\n");
    printf("end_dist_thres <= neighbors in nn_file\n");
    printf("tree goes to stdout\n");
    exit(1);
  }

  nn_file = argv[1];
  num_samples = atoi(argv[2]);
  shared_thres = atoi(argv[3]);
  min_dist_thres = atoi(argv[4]);
  max_dist_thres = atoi(argv[5]);

  /* Read in neighbor file */
  fp = fopen(nn_file, "r");
  if(!fp) {
    printf("Cannot open `%s'\n", nn_file);
    exit(1);
  }
  samples = Allocate(num_samples, int*);
  for(s1=samples,i=0;i<num_samples;s1++,i++) {
    *s1 = Allocate(max_dist_thres+1, int);
    for(j=0;j<=max_dist_thres;j++) {
      fscanf(fp, "%d", &(*s1)[j]);
    }
    while(fgetc(fp) != '\n');
  }
  fclose(fp);

  /* Initialize the partition and trees */
  p = PartitionCreate(num_samples);
  trees = Allocate(num_samples, Tree);
  for(i=0;i<num_samples;i++) {
    trees[i] = TreeCreate(IntCreate(i+BASE));
  }

  /* loop all possible partitions */
#if JP
  dist_thres = max_dist_thres;
  for(;shared_thres >= 0;shared_thres--) {
#else
  for(dist_thres = min_dist_thres;dist_thres <= max_dist_thres;dist_thres++) {
#endif
    /* Form clusters */
    PartitionRefine(p, (void*)samples, (CmpFunc*)EquivNN);

    /* Set j = size of largest class */
    j = PartitionClassSize(p,1);
    for(c=2;c <= p->num_classes;c++) {
      i = PartitionClassSize(p,c);
      if(i > j) j = i;
    }
    fprintf(stderr, "%d %d %d %d ", 
	    dist_thres, shared_thres, p->num_classes, j);
    fprintf(stderr, "\n");
    fflush(stdout);

    /* create next level of tree */
    /* loop classes */
    for(c = 1;c <= p->num_classes;c++) {
      if(PartitionClassSize(p, c) <= 1) continue;
      tree = TreeCreate(IntCreate(dist_thres));
      {PartitionIter(p,c,e) {
        TreeAddChildUnique(tree, trees[e]);
        trees[e] = tree;
      }}
    }
  }
  PartitionFree(p);

  /* put all existing trees under one tree */
  tree = TreeCreate(IntCreate(dist_thres));
  for(i=0;i<num_samples;i++) {
    TreeAddChildUnique(tree, trees[i]);
  }

  TreeWrite(stdout, tree, IntWrite);
  TreeFree(tree, free);
  exit(0);
}
Beispiel #7
0
void SetupVFS() {
    fs_tree = TreeCreate();
}