数据结构:倒排索引
来源:互联网 发布:阿里云与传统工业合作 编辑:程序博客网 时间:2024/05/18 03:32
#include <iostream>#include <map>#include <vector>#include <string.h>using namespace std;//倒排索引,以属性值来存储关键字。//找出两个人相似度最高的人,相似度=(相同爱好数)/总的爱好数。struct Node{ string like; int count; Node() { count = 0; } map<string,bool> mp;};template<int N>class MyClass{public: MyClass() { node = new Node[N]; index = 0; } ~MyClass() { if (node) delete[] node; } void Insert(char (*str)[10],int n) { int j = 0; string _name = str[j++]; for (; j < n; j++) { int i = 0; string _like = str[j]; while (node[i].count != 0 && (node[i].like != _like))i++; if (node[i].count == 0) { node[i].mp.insert(pair<string, bool>(_name, true)); node[i].like = _like; node[i].count++; } else { node[i].count++; node[i].mp.insert(pair<string, bool>(_name,true)); } } } void Printf() { int i = 0; for (; node[i].count!=0; i++) { cout << node[i].like.c_str() <<" : "; map<string,bool> :: iterator it = node[i].mp.begin(); while (it != node[i].mp.end()) { cout << (*it).first.c_str() << " "; it++; } cout << endl; } }private: int index; Node *node;};int main(){ MyClass<10> mc; char People1[][10] = { "小A", "自拍", "运动", "游戏" }; char People2[][10] = { "小B", "游戏", "听歌", "看电影" }; char People3[][10] = { "小C", "逛街", "听歌", "运动"}; char People4[][10] = {"小D","游戏","听歌","看电影","爬山"}; mc.Insert(People1,4); mc.Insert(People2,4); mc.Insert(People3,4); mc.Insert(People4,5); mc.Printf(); return 0;}
1 0
- 数据结构:倒排索引
- 倒排索引原理
- 倒排索引
- 倒排索引
- 倒排索引
- 索引 倒排
- 倒排索引
- 倒排索引
- hadoop 倒排索引
- 倒排索引技术
- 什么是倒排索引?
- 倒排索引求子串
- 倒排索引
- 倒排索引
- 倒排索引
- 倒排索引
- 倒排索引
- 倒排索引
- MongoDB shell中执行查询
- 你的充电宝能否上飞机
- R语言置换函数的定义
- MongoDB Shell中执行增
- MongoDB shell中执行删除
- 数据结构:倒排索引
- Linux内核分析(转自某大牛)
- 打钩的动画
- MongoDB shell中执行更新
- 从零开始学习Hadoop--第1章 Hadoop的安装
- unity上面调用andorid相册的插件-android部分
- RelativeLayout
- MongoDB分页、排序与游标
- Java虚拟机详解----常用JVM配置参数