关键字搜索 c语言,c语言-以关键字搜索程序
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#include
#include
#include
typedef?struct?CharList_Node{
char?*data;
int?vaul;
struct?CharList_Node?*next;
}cnode;
typedef?struct?Int_Node{
cnode?*bat;
struct?Int_Node?*next;
}intnode;
typedef?struct?IndexList_Node{
char?*info;
intnode?*code;
struct?IndexList_Node?*next;
}inode;
cnode?*CreatCharList()
{
cnode?*head,*hp,*tp;
char?*a;
char?*b="n";
int?x;
a=(char*)malloc(sizeof(char));
head=(cnode*)malloc(sizeof(cnode));
head->next=NULL;
hp=head;
printf("Input?the?CharList,compelete?by?enter?'n'?and?number?'0'.:\n");/*建立詞表,輸入字符串,以輸入“n”+”回車”以及“0”+"回車”?結束*/
while(EOF!=(scanf("%s""%d",a,&x))&&(*a!=*b))
{
tp=(cnode*)malloc(sizeof(cnode));
strcpy(tp->data,a);
tp->vaul=x;
tp->next=hp->next;
hp->next=tp;
hp=tp;
}
return?head;
}
void?PrintCharList(cnode?*phead)
{
cnode?*p;
p=phead->next;
printf("Output?the?CharList?Vaul:\n");
while(p)
{
printf("%s??""%d\n",p->data,p->vaul);
p=p->next;
}
}
intnode?*Compare(char?*x,cnode?*chead)
{
int?i;
int?j;
int?k;
char?*a;
intnode?*ptr,*hp,*tp;
cnode?*p;
ptr=NULL;
p=chead->next;
ptr=(intnode*)malloc(sizeof(intnode));
ptr->next=NULL;
hp=ptr;
while(p)
{?a=p->data;
i=0;
j=0;
k=0;
while((k
{
if(*(x+i)==*(a+j))
{
i++;
j++;
}
else
{
j=++k;
i=0;
}
if(i==(strlen(x)))
{
tp=(intnode*)malloc(sizeof(intnode));
tp->next=hp->next;
tp->bat=p;
hp->next=tp;
hp=tp;
}
}
p=p->next;
}
return?ptr;
}
void?PrintCode(intnode?*inthead)
{
intnode?*p;
p=inthead->next;
while(p)
{
printf("%d?""%s\n",p->bat->vaul,p->bat->data);
p=p->next;
}
}
void?PrintIndexList(inode?*ihead)
{
inode?*ip;
intnode?*intp;
ip=ihead->next;
while(ip)
{
printf("%s:?",ip->info);
intp=ip->code;
PrintCode(intp);
ip=ip->next;
printf("\n");
}
}
main()
{
cnode?*pp;
intnode?*pr;
inode?*ihead,*hp,*tp;
char?*a;
char?*b="n";
ihead=(inode*)malloc(sizeof(inode));
ihead->next=NULL;
hp=ihead;
a=(char*)malloc(sizeof(char));
pp=CreatCharList();
PrintCharList(pp);
printf("Please?intput?index?information?,complete?by?'n':\n");/*輸入索引關鍵字,以輸入"n"+”回車”結束*/
while(EOF!=scanf("%s",a)&&(*a!=*b))
{
pr=Compare(a,pp);
tp=(inode*)malloc(sizeof(inode));
tp->next=hp->next;
strcpy(tp->info,a);
tp->code=pr;
hp->next=tp;
hp=tp;
printf("%s:?",tp->info);
PrintCode(pr);
printf("\n");
}
printf("Press?key?of?'y'?output?the?IndexList?information,overview?by?'n':\n");/*輸入”y”+”回車”打印索引表,輸入"n"+”回車”?退出程序。*/
while(EOF!=scanf("%s",a)&&(*a!=*b))
{
PrintIndexList(ihead);
}
return?0;
}
總結
以上是生活随笔為你收集整理的关键字搜索 c语言,c语言-以关键字搜索程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言提供了6个位运算,C语言基础丨运算
- 下一篇: android自定义模态框,安卓开发自定