int CountWord(pDICT root) { if(root ==NULL) { return 0; } else { return(CountWord(root->leftlink)+ 1 + CountWord(root->rightlink)); } }
void main() { pDICT root =NULL; int iChoice =1; int Count; while(iChoice !=0) { system("cls"); printf("\t1.Create your Dictionary.\n"); printf("\t2.Load Dictionary.\n"); printf("\t3.Look up word.\n"); printf("\t4.Delete word.\n"); scanf("%d", &iChoice); fflush(stdin); switch(iChoice) { case 1: root = MakeDictionary(); break; case 2: PrintDictionary(root); Count = CountWord(root); printf("Dictionary have %d word.\n",Count); break; case 3: LookUpWord(root); break; case 4: DeleteWord(root); break; } getch(); } }
int main(int argc, char *argv[]) { int chars_read=1; if (argc < 2) { printf("Usage wf int size of hashtable\n"); return 1; } tablesize = atoi(argv[1]); printf("calling create table\n"); htable = createTable(tablesize, (void *) hashcode, (void *) toString, (void *) freeWordObj, (void *) compareTo); printf("table created with table size %d\n", tablesize); char * line = NULL; while (chars_read>-1){ chars_read = getline(&line, &maxlinelength, stdin); token = strtok(line, delimiters); while (token != NULL) { CountWord(htable, token); token = strtok(NULL, delimiters); // if (token!=NULL){ //CountWord(htable, token); // printf("tokenized\n"); // } } } printf("finished sample\n"); printTable(htable); printf("ran printTable\n"); freeTable(htable); printf("ran freetable\n"); return 0; }