该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#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;
}