c语言 英文单词频率统计 哈希存储

使用C语言对英文文章进行单词频率统计,通过哈希存储技术高效查找最高频单词,同时计算单词种类和总数。
摘要由CSDN通过智能技术生成

c语言 英文单词频率统计 哈希存储

从一段英文文章中找到频率最大的几个单词,同时统计不同单词个数以及总单词个数,利用哈希进行存储。

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>

#define HASH_TABLE_SIZE 49999

typedef struct word{
	char wrd[80];
	int num;
}word;
static int diff_words=0;	
static int total_words=0;

word *hashtable[HASH_TABLE_SIZE];

int hash(int number){
    return number%HASH_TABLE_SIZE;
}
void insert(int count,char *w)
{
	int pos=hash(count);
	word *newWord;
	total_words++;
	while (hashtable[pos])
	{
		if(!strcmp(hashtable[pos]->wrd,w))
		{
			hashtable[pos]->num++;
			return;
		}			
		else
		{
			pos++;
		}
	}
	newWord=(word*)malloc(sizeof(word));
	newWord->num=1;
	strcpy(newWord->wrd,w);
	hashtable[pos]=newWord;
	diff_words++;
}


int main()
{
	FILE *fp;
	char wrd_temp[80],ch;
	word *head,*curr;
	int i,
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值