词频统计(未完成,错误)
Posted astonc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了词频统计(未完成,错误)相关的知识,希望对你有一定的参考价值。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> using namespace std; #define KEYLENGTH 15 #define MAXWORDLEN 80 #define MAXTABLESIZE 100000 typedef char ET[KEYLENGTH+1]; typedef int Index; typedef struct LNode* PtrToLNode; struct LNode{ ET Data; PtrToLNode Next; int Count; }; typedef PtrToLNode Position; typedef PtrToLNode List; typedef struct TblNode *HashTable; struct TblNode{ int TableSize; List Heads; }; int flag,cnt; vector<LNode> v; bool cmp(LNode a,LNode b){ if(a.Count > b.Count ) return true; if(a.Count ==b.Count ){ if(strcmp(a.Data,b.Data)<0) return true; } return false; } int NextPrime( int N ){ int i, p = (N%2) ? N+2 :N+1; while(p<=MAXTABLESIZE){ for(i=(int)sqrt(p); i>2; i--) if(! (p%i)) break; if(i == 2) break; else p += 2; } return p; } HashTable CreateTable( int TableSize){ HashTable H; int i; H = (HashTable)malloc(sizeof(struct TblNode)); H->TableSize = NextPrime(TableSize); H->Heads = (List)malloc(H->TableSize *sizeof(struct LNode)); for( i=0; i<H->TableSize ; i++){ H->Heads [i].Data[0] = ‘