Exemple #1
0
void treeprint2(struct tnode2* p){

  int i, c;

  if (p!= NULL){
    treeprint2(p->left);
    for ( i = 0; i < p->size; i++){
      printf("%d: ", p->count);
      printf("%s\n", p->words[i]);
    }
    treeprint2(p->right);
  }
}
void treeprint2(struct treenode *node){

  struct lines *temp;
  
  if(node != NULL){
    treeprint2(node->left);
    printf("Count:%4d::\tWord: %s ::\tLines: ", node->count, node->word);
    for(temp = node->startinglinelist; temp != NULL; temp = temp->next){
      printf("%4d ", temp->linenumbervalue);
    }
    printf("\n");
    treeprint2(node->right);
  }
}
int ex6_3(int argc, char *argv[]){

  struct treenode *root;
  char word[100];
  int linenumber = 1;

  root = NULL;

  while(getwordch6(word, 100) != EOF){
    //in here we now need to deal with words returned with a \n in them, basically setting the \n to \0
    int len = strlen(word);
    int foundnewline = 0;

    if(word[len-1] == '\n'){
      foundnewline = 1;
      word[len-1] = '\0';
    }

    if(isalpha(word[0]) && !checkfornoisewords(word)){
      root = addtree2(root, word, linenumber);
    }

    if(foundnewline == 1){
      linenumber++;
      foundnewline = 0;
    }
  }

  treeprint2(root);

  return 0;
}
Exemple #4
0
/* word frequency count */
int main() {
	struct tnode *root, *freqroot;
	char word[MAXWORD];
	char *key[MAXKEYLIST]={NULL,};
	root = NULL;
	freqroot = NULL; // 새로운 트리를 위한 뿌리 노드를 만들어야 한다.
	while (getword(word, MAXWORD) != EOF)
		if (isalpha(word[0]))
			root = addtree(root, word);
	freqroot = createtreefromtree(root, freqroot);
	 treeprint(root);
     printf("==END::raw tree==\n");
	treeprint2(freqroot);
    printf("==END::freq tree==\n");
	inorder_traversal(root,key);
	int ti=0;
	while(key[ti]!=NULL){
        //if(ti<10){
		root=reducetree(root,key[ti++]);
        //}
		//printf("%s\n",key[ti++]);
	}
	//printf("end key list\n");
	treeprint(root);
	printf("finish print\n");
	return 0;
}
Exemple #5
0
int main(){

  struct tnode *root;
  char word[MAXWORD];

  root = NULL;
  root2 = NULL;
  while (getword(word, MAXWORD) != EOF)
    if (isalpha(word[0]))
      root = addtree(root, word);

  root2 = tnodetotnode2(root);
  treeprint2(root2);

  return 0;
}