Beispiel #1
0
void printTrie(const TrieNode & node, string & word) {
	/*
	 *	if current node is not a sentry for end
	 *		put holding character to word;
	 *	else
	 *		print word
	 *		return
	 *
	 *  for each valid next node
	 *		printTrie (next node, word)
	 *	pop out the last character from string
	 */

	if (node.c != END_OF_WORD) {
		word.push_back(node.c);
	} else {
		cout << word << endl;
		return;
	}

	for (int i = 0; i < NUM_LETTER; ++i) {
		if (node.next[i] != NULL)
			printTrie(*(node.next[i]), word);
	}
	word.erase(word.end() - 1);
}
 void printTrie(int trieIndex, int depth)
 {
     for(int i=0;i<depth;++i)
     {
         printf(" ");
     }
     printf("%c\n",trieNode[trieIndex].character);
     if(trieNode[trieIndex].child)
     {
         printTrie(trieNode[trieIndex].child, depth + 1);
     }
     if(trieNode[trieIndex].right)
     {
         printTrie(trieNode[trieIndex].right, depth);
     }
 }
Beispiel #3
0
int main(int argc, const char * argv[])
{
    if(argc != 3){
        fprintf(stderr, "invalid input\n");
        return 1;
    }
    
    FILE *dictFilePtr = fopen(argv[1], "r");
    if(dictFilePtr == NULL) {
      fprintf(stderr, "Cannot open the dictionary file\n");
      return 1;
    }
    
    FILE *dataFilePtr = fopen(argv[2], "r");
    if(dataFilePtr == NULL) {
        fprintf(stderr, "Cannot open the data file\n");
        return 1;
    }
    
    readDict(dictFilePtr);
    fclose(dictFilePtr);
    scanData(dataFilePtr);
    fclose(dataFilePtr);
    
    printTrie();
    
    return 0;
}
Beispiel #4
0
void printTrie(Tree *dic) {
    Tree current = *dic;
    printf("\n");
    for (int i = 0; (current -> childChar)[i]; i ++) {
        Tree child = (current -> children)[i];
        printf("%c  :  code : %d\n",(current -> childChar)[i], child -> code);
        printTrie(&(current -> children)[i]);
        printf("\n NEXT BRANCH \n");
    }
}
 void printTrie(TrieNode &node, int depth)
 {
     for(int i=0;i<26;++i)
     {
         if(node.next[i])
         {
             for(int j=0;j<depth;++j)
             {
                 printf(" ");
             }
             printf("%c\n", i + 'A');
             printTrie(trieNode[node.next[i]], depth + 1);
         }
     }
 }
Beispiel #6
0
// printTrie()
void printTrie(FILE* out, FILE* dup, Node* n, int pos,
    int* leaf, int* rem) {
  if (n == NULL)
    return;

  for (int i = n->st; i < n->end; i++)
    line[pos++] = n->seq[i];
  if (n->child[0] == NULL) {
    line[pos] = '\0';
    fprintf(out, ">%s\n%s\n", n->head, line);
    (*leaf)++;
  }
  for (int i = 0; i < CHILD; i++)
    if (n->child[i] != NULL)
      printTrie(out, dup, n->child[i], pos, leaf, rem);
    else
      break;
}
Beispiel #7
0
static void printTrie(TrieNode* node)
{
	int c;
	printf("[");
	for(c = 0; c < N_TRIE_CHILDREN; c++)
	{
		if(node->children[c] != NULL)
		{
			putchar((char)(c + FIRST_ASCII_CH));
			if(node->children[c]->isWord)
			{
				putchar('*');
			}
			printTrie(node->children[c]);
		}
	}
	printf("]");
}
Beispiel #8
0
// getParams
void getParams(int argc, char** argv) {

  char* outFile = NULL, *inFile = NULL, *dupFile = NULL;

  // parse argv
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], HELP))
      usage();
    else if (i < argc - 1) {
      if (!strcmp(argv[i], OUTFILE))
        outFile = argv[++i];
      else if (!strcmp(argv[i], INFILE))
        inFile = argv[++i];
      else if (!strcmp(argv[i], DUPFILE))
        dupFile = argv[++i];
    } else
      usage();
  }

  if (outFile == NULL || inFile == NULL)
    usage();

  FILE* out = NULL, *dup = NULL;
  openFiles(outFile, &out, dupFile, &dup);

  parseFiles(inFile);

  int leaf = 0, rem = 0;
  for (int i = 0; i < CHILD; i++)
    printTrie(out, dup, root->child[i], 0, &leaf, &rem);
  printf("Leaf reads:   %10d\n", leaf);
  if (dup != NULL)
    printf("Removed reads:%10d\n", rem);

  if (fclose(out) || (dup != NULL && fclose(dup)))
    exit(error("", ERRCLOSE));
}