编程C++ 功能:输入一页文字,程序可以统计出文字、数字、空格的个数。。。
"#include
#include
#include
#include
#include
typedef
TreeItem;
struct
ch[256];
}work[256];
typedef
struct
btnode
*btlink
typedef
struct
btnode
TreeItem
WORD;//字符串
btlink
right
parent
count;
BtNode
typedef
struct
bstree
*Tree
typedef
struct
bstree
btlink
根结点指针
}BSTree;
Init()
(Tree)malloc(sizeof(T));
T->root
return
btlink
NewNode(char
btlink
if((p=(btlink)malloc(sizeof(BtNode)))==0)
cout<<"开辟失败!"<
exit(0);
p->WORD=x;
p->left=0;
p->right=0;
p->parent=0;
p->count=1;
return
less(char
x,char
return
(strcmp(x,y)<0);//x
Search(TreeItem
btlink
while(p)
less(x,p->WORD)
p->left
less(p->WORD,x))
p=p->right;
break
if(p){
cout<<"有找到"<
cout
cout<<"木有找到"<
InOrder(btlink
if(t)
InOrder(t->left);
cout<<"字符串:"
cout<<"个数:"
InOrder(t->right);
Insert(char
,Tree
btlink
p,r,pp=NULL
T->root
while(
保存父结点
通过和根结点比较,选取要搜索的子树
if(less(x,p->WORD))
p->left
if(less(p->WORD,x))
p->right
p->count++;
return
元素x已存在于字典中
NewNode(x);
if(T->root)
if(less(x,pp->WORD))
pp->left
pp->right
r->parent
T->root
open(Tree
seps[]="
,.\t\n;?:";
*taken;
filename[20];
cout<<"输入你所要打开(OPEN)的文件名:"<
cin>>filename;
cout<
if((fp=fopen(filename,"r"))==NULL)
printf("cannot
file!\n");
exit(0);
while(!(feof(fp)))
fscanf(fp,"%s",work[k++].ch);//这里还真不能用char
str【256】
taken=strtok(work[k-1].ch,seps);
while(taken!=NULL)
Insert(taken,T);
taken=strtok(NULL,seps);
fclose(fp);
add()
filename[20];
cout<<"输入你所要打开(OPEN)的文件名:"<
cin>>filename;
cout<
if((fp=fopen(filename,"a"))==NULL)
//追加文本
printf("cannot
file!\n");
exit(0);
cout<<
"输入要增加的内容
以@为结束"<
getchar();
ch=getchar();
while(ch!=@)
fputc(ch,fp);
ch=getchar();
fclose(fp);
find(Tree
cout<<"输入要查找的内容:"<
WORD[256];
gets(WORD);
cout<
w=WORD;
btlink
p=T->root;
Search(w,p);
main()
btlink
btlink
loop:cout<<"功能选取:"<
cout<<"1
打开(OPEN)文件"<
cout<<"2
中序显示"<
cout<<"3
增加文本内容"<
cout<<"4
查找"<
cin>>cs;
switch(cs)
T=Init();
open(T);
loop;
p=T->root
InOrder(p);
loop;
add();
loop;
find(T);
loop;
你要有建个txt的文档
a.txt就可以
我开始做了挺久的"