diff options
Diffstat (limited to 'c/dataStructure/栈和队列/栈/链栈/palindrome.c')
-rwxr-xr-x | c/dataStructure/栈和队列/栈/链栈/palindrome.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/c/dataStructure/栈和队列/栈/链栈/palindrome.c b/c/dataStructure/栈和队列/栈/链栈/palindrome.c new file mode 100755 index 0000000..c8a9a7f --- /dev/null +++ b/c/dataStructure/栈和队列/栈/链栈/palindrome.c @@ -0,0 +1,64 @@ +#include<ctype.h> +#include "stack.h" + +int main(void) +{ + ElemType ch,a1,a2; + Stack s,p; + int size = 0; + bool flag = false; + + InitStack(&s); + InitStack(&p); + + while ((ch = getchar()) != '\n') + { + Push(&s,tolower(ch)); + size++; + } + + if (size == 0) + return 0; + if (size % 2 == 0) + flag = true; + size /= 2; + + if (!flag) + size++; + + for (int i = 0; i < size; i++) + { + if (flag) + { + Pop(&s,&ch); + Push(&p,ch); + } + else + { + if (i == size - 1) + ch = GetTop(&s); + else + Pop(&s,&ch); + Push(&p,ch); + } + } + + while (s) + { + Pop(&s,&a1); + Pop(&p,&a2); + if (a1 != a2) + break; + } + + if (s) + { + printf("Not palindrome word!\n"); + DestroyStack(&s); + DestroyStack(&p); + } + else + printf("Is palindrome word!\n"); + + return 0; +}
\ No newline at end of file |