blob: 8a627a940142c3023fd6665a21b4e48cbf71d5bd (
plain) (
blame)
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
|
#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);
}
|