91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-13
  • 語言: C/C++
  • 標簽: 詞頻統計??

資源簡介

內容 (1)從文件中讀出一篇英文文章,將不同的單詞存入堆中,建立相應的索引表確定各單詞在堆中存儲的位置及出現的次數。 (2)按單詞出現的頻率遞減的次序輸出。

資源截圖

代碼片段和文件信息

#include?
#include
#include
#define?MaxSize?100
#define?MaxLen???20
#define?MaxWord??10
typedef?struct
{??char?data[MaxLen];
???int??len;
}SqString;//單詞讀取

typedef?struct
{
??int?addr;
??int?len;
??int?fre;//存儲頻度
}idxtem;//索引表

typedef??struct
{
???char??space[MaxSize];
???int??free;
???idxtem??item[MaxWord];
???int?last;
}idxlist;//堆

void?init(idxlist?*&List)
{
???List=(idxlist?*)malloc(sizeof(idxlist));
???List->free=0;
???List->last=-1;
}

void?create_sq(SqString?&strFILE?*fp1)//單個單詞
{

???str.len=0;
???int?i=0;
???char?ch;
??while(!feof(fp1))//判斷文件是否結束
{
??????ch=fgetc(fp1);//用fgetc函數從文件讀入一個字符
??if(((ch<‘A‘)||(ch>‘Z‘))&&((ch<‘a‘)||(ch>‘z‘)))
??break;
??str.data[i]=ch;
??str.len++;
??i++;
}
?
}
void?create(idxlist?*List)
{????idxtem?q;
????SqString?str;
int?igjmk1k2;
?FILE?*fp1=fopen(“E:\\2.txt““r+“);//文件指針名=fopen(文件名,使用文件方式)
???while(!feof(fp1))
{?????k1=0k2=0;
??create_sq(strfp1);
??for(j=-1;j<=List->last;j++)
??{
??if(List->item[j].len==str.len)//先比較長度,長度與之前不同,入堆棧長度相同順序比較字母
??{
??for(m=0;m ??{
??if(List->space[List->item[j].addr+m]!=str.data[m])//有字母不同,入堆棧
??{g=0;break;}
??else
??g=1;
??}

評論

共有 條評論