stoptree.cc

来自「一个增量文本聚类的算法。 参考文献: Wai-chiu Wong, Ada 」· CC 代码 · 共 77 行

CC
77
字号
#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <iostream.h>#include "StopTree.h"#include "Word.h"StopTree::StopTree(){    FILE *in;    char str[MaxWordLen];    stopRoot = NULL;    if((in=fopen("../MyLib/stoplist","r")) == NULL){        cerr << "Cannot open the stoplist file\n";        exit(1);    }    while(!feof(in)){	fscanf(in,"%s",&str);	insert(&stopRoot,str);    }//    printTree(stopRoot);    fclose(in);}StopTree::~StopTree(){}void StopTree::insert(Word **root,char *str){    if((* root) == NULL){    	(* root) = new Word(str);    }else{	int s;	s = strcmp((* root)->nameList->name,str);	if(s > 0){	    insert(&((* root)->left),str);	}else if(s < 0){	    insert(&((* root)->right),str);	}    }}void StopTree::printTree(Word *root){    if(root->left != NULL){	printTree(root->left);    }    printf("%s\n",root->nameList->name);    if(root->right != NULL){	printTree(root->right);    }}int StopTree::inStopList(Word *root,char *str){    int l=0;    if(root == NULL){        l = 0;    }else if(strcmp(root->nameList->name,str) > 0){        l = inStopList(root->left,str);    }else if(strcmp(root->nameList->name,str) < 0){        l = inStopList(root->right,str);    }else{	l = 1;    }    return l;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?