【问题描述】
中文信息处理中常用到汉字的字频统计,设计一个小工具统计输出文本的字频。
【基本要求】
(1)输入一个中文文本。
(2)输出形式:三种排序:①按汉字出现顺序输出的字频,②按汉字拼音(区位码)顺序输出的字频,③按字频逆序(同频时按汉字区位码序)输出的字频。
【测试数据】
输入:天天吃食堂的面食
输出形式1:
天2
吃1
食2
堂1
的1
面1
输出形式2:
吃1
的1
面1
食2
堂1
天2
输出形式3:
食2
天2
吃1
的1
面1
堂1
【代码】
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<fstream>
#include<string>
#include<cstring>
#include<sstream>
#define NUM 10
using namespace std;
class ziNode//汉字节点
{
public:
string hanzi;//汉字-字符串
int zp;//汉字字频
string qwm;//汉字的区位码-字符串
bool operator==(ziNode& t)//==运算符重载
{
if(hanzi==t.hanzi)
return true;
else
return false;
}
ziNode& operator=(ziNode& t)//=运算符重载
{
hanzi=t.hanzi;
zp=t.zp;
qwm=t.qwm;
return *this;
}
};
int defaultSize=6768;
template<class T>
class SeqList//顺序表-存储汉字节点
{
public:
T *data;//动态数组
int maxSize;//顺序表最大容量
int last;//顺序表表长
void reSize(int newSize);
SeqList(int sz=defaultSize);
SeqList(SeqList<T>& L);
~SeqList(){
delete[] data;}
int Size() {
return maxSize;}
int Length(){
return last+1;}
int Search(T& x);
int Searchqwm(char p[]);//返回指定区位码在顺序表中的下标
int Locate(int i);
bool getData(int i,T&x)
{
if(i>0&&i<=last+1)
{
x=data[i-1];
return true;
}
else return false;
}
void setData(int i,T& x)
{
if(i>0&&i<=last+1)
{
data[i-1]=x;
}
}
bool Insert(int i,T& x);
bool Remove(int i,T& x);
bool IsEmpty()
{
return (last==-1)?true:false;
}
bool IsFull()
{
return (last==maxSize-1)?true:false;
}
bool IsExist(T& x);//判断节点是否存在
void order1();//第一种排序
void order3();//第三种排序
};
template <class T>
SeqList<T>::SeqList(int sz)
{
if(sz>0)
{
maxSize=sz;
last=sz-1;
data=new T[maxSize];
}
}
template <class T>
SeqList<T>::