From cf3a29feb5887344b6633ead1b4b6d5657a15a4b Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sun, 15 Jun 2014 03:24:33 +0200
Subject: old stuff: algorithms
---
algorithms/palindrome.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 algorithms/palindrome.cc
(limited to 'algorithms/palindrome.cc')
diff --git a/algorithms/palindrome.cc b/algorithms/palindrome.cc
new file mode 100644
index 0000000..d39382c
--- /dev/null
+++ b/algorithms/palindrome.cc
@@ -0,0 +1,49 @@
+#include
+
+using namespace std;
+
+
+int
+chrcmp(char a, char b) {
+ if(a == b) {
+ return 0;
+ }
+
+ return 1;
+}
+
+int
+test_palindrome(string str, int len)
+{
+ int i=0, j=len-1;
+
+ while(i < len-1) {
+ if(str[i] == 32) {
+ i++;
+ } else if(str[j] == 32) {
+ j--;
+ } else {
+ if(chrcmp(str[i], str[j])) {
+ return 1;
+ }
+ i++;
+ j--;
+ }
+ }
+
+ return 0;
+}
+
+int main()
+{
+ string str = "a man a plan a canal panama";
+ int len = str.length();
+
+ if(test_palindrome(str, len)) {
+ cout << "\"" << str << "\" is no palindrome!" << endl;
+ }
+ else {
+ cout << "\"" << str << "\" is a palindrome!" << endl;
+ }
+}
+
--
cgit v1.2.3