Home > Back-end >  Excuse me why my next array wrong??
Excuse me why my next array wrong??

Time:12-18

# include
# include
# include
# include

using namespace std;

Typedef char SString [1000].
Int next [1000];
Int nextval [1000].

Void get_next (SString T, int next [])
{
Int I=1, j=0;
Next [1]=0;
While (I {
If (j==0 | | T==[I] T [j])
{
++i;
+ + j;
Next [I]=j;
}
The else
J=next [j];
}
}
Void get_nextval (SString T, int nextval [])
{
Int I=1, j=0;
Nextval [1]=0;
While (I {
If (j==0 | | T==[I] T [j])
{
++i;
+ + j;
If (T [I]!=T [j])
Nextval [I]=j;
The else
Nextval [I]=nextval [j];
}
The else
J=nextval [j];
}
}

Int main ()
{
SString S, T;
Gets (T);
//gets (S);

T [0]=strlen (T);
S [0]=strlen (S);
Get_next (T, next);
Get_nextval (T, nextval);
int i,j;
for(i=1; I <=T [0]; I++)
Printf (" % 3 d ", next [I]);
//for (j=1; J <=T [0]; J++)
//printf (" % 3 d, "nextval [j]);
return 0;

}
  • Related