Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar06 / Linked-List-Palindrome.cpp
diff options
context:
space:
mode:
Commitac43d43d4b9a67b47b02648fc1bb0153191673e9 (patch)
Author
 Stoycho Kyosev <68247567+stoychoX@users.noreply.github.com>
2022-11-10 00:46:45 +0200
Committer
 GitHub <noreply@github.com>
2022-11-10 00:46:45 +0200
Files403dbf990c7c8a7c57d44cb6958e516645748a45 /Seminar06/Linked-List-Palindrome.cpp
Data-structures-and-algorithms-ac43d43d4b9a67b47b02648fc1bb0153191673e9.tar
Data-structures-and-algorithms-ac43d43d4b9a67b47b02648fc1bb0153191673e9.tar.gz
Data-structures-and-algorithms-ac43d43d4b9a67b47b02648fc1bb0153191673e9.zip
Parentbc78a4c3afdd93f6c3f32760e76ddce83af87a3e (diff)
Update and rename Linked-List-Perm.cpp to Linked-List-Palindrome.cpp
1 files changed, 28 insertions, 0 deletions
-rw-r--r--Seminar06/Linked-List-Palindrome.cpp28
diff --git a/Seminar06/Linked-List-Palindrome.cpp b/Seminar06/Linked-List-Palindrome.cpp
new file mode 100644
index 0000000..8a627a9
--- /dev/null
+++ b/Seminar06/Linked-List-Palindrome.cpp
@@ -0,0 +1,28 @@
+#include"../Seminar04/linked-list-utils.h"
+
+bool isLinkedListPalRec(const LinkedListNode<int>*& begin, const LinkedListNode<int>* end) {
+ if(end == nullptr)
+ return true;
+
+ bool res = isLinkedListPalRec(begin, end->next) && (begin->data == end->data);
+
+ begin = begin->next;
+ return res;
+}
+
+template<class T>
+bool isLinkedListPal(const LinkedListNode<T>* ll) {
+ if(ll == nullptr)
+ return true;
+
+ const LinkedListNode<int>* begin = ll;
+ const LinkedListNode<int>* end = ll;
+
+ return isLinkedListPalRec(begin, end);
+}
+
+int main() {
+ LinkedListNode<int>* ll = new LinkedListNode(0, new LinkedListNode(1, new LinkedListNode(1)));
+
+ std::cout << isLinkedListPal(ll);
+}