Home > Back-end >  Soft 2 jmu data structure, master ye group experiment, discussion
Soft 2 jmu data structure, master ye group experiment, discussion

Time:04-23

data structure course requirements in the BBS for group discussion, this is the master, ye group experimental discussion post

CodePudding user response:

first experiment: PTA: string is symmetrical

CodePudding user response:

Equal to directly compare whether the fore and aft
 
Bool palindrome (char * s)
{
Int n, I;
N=strlen (s) - 1;
for(i=0; i<=n/2; I++)
If (s [I]!=s/n - I)
return false;
return true;
}

array was used to simulate the stack, the first half of characters into the stack, in the stack and the second half character comparison
 
Bool palindrome (char * s)
{
Int mid and top=1, I=0;
Char xn [200]={0};
Mid=strlen (s)/2;
While (I!=mid)
{
Top++;
Xn [top] [I]=s;
i++;
}
If (strlen (s) % 2==1 & amp; & Strlen (s)!
=1)i++;
While (I!=strlen (s) - 1)
{
If (xn [top]! [I])
=sreturn false;
The else
{
Top -;
i++;
}
}
return true;
}

CodePudding user response:

Leaf sauce really handsome!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

 bool Ispalindrome (SqStack * & amp; S) {
SqStack * q;
InitStack (q);
int i=0;
Char e;
While (StackEmpty (s)) {
GetTop (s, e);
Pop (s, e);
Push (q), e);
}
for(i=0; i<=MaxSize; I++) {
If (q - & gt; Data [I]!=s - & gt; Data [I])
break;
}
if(i!=MaxSize)
return true;
The else
return false;
}

InitStack (q) : for function initializes the
GetTop (s, e) on the top of the stack elements, and assigned to e
According to the stack "last in, first out" principle, for return stack operation, and will return the element into the stack q, after comparing the q and s can
  • Related