资源简介
读入文本集,建立倒排索引,内含有的TXT文本可以替换,源代码可以直接运行
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
class node
{
friend class suoyin;
public:
char * name;
node * next;
bool d1; //记录name是否在第一个文档中
bool d2; //记录name是否在第二个文档中
node(){d1=false;d2=false;}; //初始化 设为不存在
node(char * a); //初始化,将外部字符串设为name
};
node::node(char * a)
{//初始化,将外部字符串设为name
name = new char [];
name = a;
}
class suoyin
{//倒排索引类
public:
node * root ;//记录根节点,创建链表记录倒排索引
suoyin(){root = NULL;}//初始化 root
suoyin & addnode(int knode & a);//将外部节点加入倒排索引
suoyin & delenode();//删除重复名字的节点,并且将记录表合并
int * find(char * x);//按名字查找记录,并且返回记录表(为一个int数组)
void output1();//打印在屏幕上
void output2();//打印在“il.txt“中
};
suoyin & suoyin::addnode(int knode & a)
{//将外部节点加入倒排索引
node * p=root;
for(int i=1;i p=p->next;//寻找到最后一个节点
node * y =new node;//新建节点y作为桥梁,将新节点加入
y->name=a.name;
y->d1=a.d1;
y->d2=a.d2;
if(k!=0)//加入的不是首节点
{
y->next=p->next;
p->next=y;
}
if(k==0)//加入的是首节点
{
y->next=root;
root=y;
}
return * this;//返回新的倒排索引
}
suoyin & suoyin::delenode()
{//删除重复名字的节点,并且将记录表合并
node * p = root;
while (p->next)//遍历倒排索引
{
if (!strcmp(p->next->namep->name))//当名字相同时
{//合并记录表,并将第二个节点删除
p->d1=p->d1+p->next->d1;
p->d2=p->d2+p->next->d2;
p->next=p->next->next;
}
else p=p->next;//名字不同时,放过
}
return * this;//返回新的倒排索引
}
int * suoyin::find(char * a)
{//按名字查找记录,并且返回记录表(为一个int数组)
int results[2];//记录查询结果
results[0]=-1;//先初始化为-1
results[1]=-1;
node * current=root;
while(strcmp(current->namea)!=0)
{
current=current->next;
}
if(current)//找到对应的名字
{//返回相应的记录表
results[0]=current->d1;
results[1]=current->d2;
return results;
}
return results; //没找到对应的名字,返回值为-1的记录表
}
void suoyin::output1()
{//打印在屏幕上
node * current;
for(current=root;current;current=current->next)
{
int fre=current->d1+current->d2;
cout<name<<“ fre:“< if(current->d1) cout<<“ ->1“;
if(current->d2) cout<<“ ->2“;
cout< }
}
void suoyin::output2()
{//打印在“il.txt“中
ofstream fout1(“il.txt“);
node * current;
for(current=root;current;current=current->next)
{
int fre=current->d1+current->d2;
fout1<name<<“ fre:“< if(current->d1) fout1<<“ ->1“;
if(current->d2) fout1<<“ ->2“;
fout1< }
fout1.close();
}
void change (node & xnode & y)
{//外部函数,按名字排列时,交换两个词项的顺序
char * temp=new char [strlen(x.name)+1];//交换名字
strcpy(tempx.name);
strcpy(x.namey.name);
strcpy(y.nametemp);
bool dtemp=x.d1;//交换记录表
x.d1=y.d1;
y.d1=dtemp;
bool ddtemp=0;
ddtemp=x.d2;
x.d2=y.d2;
y.d2=ddtemp;
};
void copy(char * achar * bint iint j)
{//外部函数,将a字符串的第i位到第j位复制到b字符串中,处理布尔查询表达式时用
int count;
for(count=0;count {
b[count]=a[i+count];
}
b[count]=‘\0‘;
};
int main()
{
char a[80][80];//二维数组存放初始词项
ifstream fin1(“1.txt“);
ifstre 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 75 2013-09-24 21:35 1.txt
文件 80 2013-09-24 21:35 2.txt
文件 7061 2013-10-09 14:45 dd.cpp
文件 566 2013-10-09 14:44 il.txt
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
川公网安备 51152502000135号
评论
共有 条评论