3.2.2统计文本算法及实现··············7
3.2.3统计数字、字母和空格个数算法及实现······7
3.2.4文本输出算法及实现··············8
(2)统计文本算法及实现
统计文本时,只需要遍历整个链表,计数加一,具体代码如下:
//统计文章的总字数
int Count_All_Word(LINE * &head)
{ LINE *p=head; //保存链表的首地址
int count=0; //总字母数
do
{count+=strlen(p->data);}
while((p=p->next)!=NULL);
return count;
}
(3)统计数字、字母和空格个数算法及实现
在统计数字、字母和空格个数时,我采用的是遍历整个链表,如果遍历链表的元素等于数字、字母或空格的ASS
//统计空格数
int Count_Space(LINE * &head)
{ LINE *p=head;
int asc_space=32; //空格的ASCIC 码值
int count=0;
do
{
int Len=strlen(p->data);
for(int i=0;i
if(p->data[i]==asc_space)count++;
}
while((p=p->next)!=NULL);
return count;
}
//统计数字数
int Count_Num(LINE * &head){
LINE *p=head;
int count=0;
do
{
int Len=strlen(p->data);
for(int i=0;i
if(p->data[i]>=48 && p->data[i]<=57)count+
}
while((p=p->next)!=NULL);
return count;
}
// 统计字母数
int Count_ZM(LINE * &head)
{ int count=Count_All_Word(head);
int space_count=Count_Space(head);
int num_count=Count_Num(head);
return count-space_count-num_count;
}
(4)文本输出算法及实现
文章输出时,也是采用遍历链表的方法,实现代码如下:
//向屏幕输出 文章
void OutPutTxt(LINE * &head){
LINE *p=head;
do
} while((p=p->next)!=NULL);
}