70,037
社区成员
发帖
与我相关
我的任务
分享
int i,j,k;
char s[2000][40]; //认为一个单词不超过40个字符
char cmp[40];
...取词
for(i=1;i<2000;i++) //在内存排序
for(j=1;j<2000-i;j++)
{
if( (strcmp(s[j],s[j-1]<0 ))
{
strcpy(cmp,s[j]);
strcpy(s[j],s[j-1]);
strcpy(s[j-1],cmp);
}
}
wordlist ws;//词库
word curword;//当前词语
char[] str="abcd";
curword.chars = str;//获取词语信息,这里只是示意,实际需要从文件读取
curword.next = NULL;
unsigned int indexone = curword.chars[0] - 'a';//一级索引
unsigned int indextwo = curword.chars[1] - 'a' + 1;//二级索引,注意如果只有一个字母要特殊处理为0
indextwo *curindex =&( ws.indexone[indexone].indextwo[indextwo] );//获取二级索引位置。
//下面就可以在二级索引下的词语链表里搜索"abcd"适当的位置了。也就是简单的单链表查询和插入操作。struct word{
char *chars;//单词
word *next;//下个单词
};
struct wordlist{
indexone[26];//一级索引
};
struct indexone{
indextwo[27];//二级索引
};
struct indextwo{//二级索引下的单词链
word *head;//第一个单词
word *tail;//第二个单词
};