-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindromeCheck.cpp
40 lines (34 loc) · 907 Bytes
/
palindromeCheck.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Created by shiby on 23-6-9.
//
#include "struct/deque.h"
#include <iostream>
bool palindrome_check(const std::string &s) {
bool ret = true;
DeQueue<char> dq;
for (char it: s) {
std::cout << it << std::endl;
dq.push_back(it);
}
for (int i = 0; i < dq.size() / 2; ++i) {
const char ch1 = dq.front();
const char ch2 = dq.back();
if (ch1 == ch2) {
dq.pop_back();
dq.pop_front();
continue;
} else {
ret = false;
}
}
return ret;
};
int main() {
std::string s = "abc";
bool is_pal = palindrome_check(s);
std::cout << "the string '" << s << "' palindrome check result is " << is_pal << std::endl;
s = "radar";
is_pal = palindrome_check(s);
std::cout << "the string '" << s << "' palindrome check result is " << is_pal << std::endl;
return 0;
}