12222

#include 
#include 
#include 
#define YES 1
#define NO 0
#define NUM 26
struct trie
{
   trie * next[NUM];
   int isword;
};
trie head,*t,*s;
int Max;
char str1[100];
int exist(trie &head,char x[])
{
   s=&head;
   for(;*x;*x++)
       if(s->next[*x-'a']==NULL)
	return NO;                           
       else s=s->next[*x-'a'];
   return YES;
}
trie* Create() 
{
    trie* p = (trie*)malloc(sizeof (trie));
    for (int i = 0; i < NUM; i++)
        p->next[i] = NULL;
    p->isword = NO;
    return p;
}
int insert(trie &head,char x[])
{
   int cnt = 0;
   s=&head;
   char *p=x;
   for(;*x;*x++)
   {
       if(s->next[*x-'a']==NULL) 			 
		   s->next[*x-'a'] = Create();
        s=s->next[*x-'a'];
		if(s->isword)
		{
			cnt++;
			Max = Maxisword)
   {
		s->isword=YES;
		cnt++;
		Max = Maxnext[i]==NULL) continue;
		deltrie(current->next[i]);
	}
	free(current);
	current=NULL;
}
void inittrie(trie &head)
{
	int i;
	for(i=0;i

你可能感兴趣的:(C/C++)