Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar06 / Linked-List-Palindrome.cpp
blob: 256246afd7b7aa21306451f30b11f0f911f90dd1 (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
29
#include"../Seminar04/linked-list-utils.h"

template<class T>
bool isLinkedListPalRec(const LinkedListNode<T>*& begin, const LinkedListNode<T>* 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<T>* begin = ll;
    const LinkedListNode<T>* end = ll;
    
    return isLinkedListPalRec(begin, end);
}

int main() {
    LinkedListNode<int>* ll = new LinkedListNode(0, new LinkedListNode(1, new LinkedListNode(1)));

    std::cout << isLinkedListPal(ll);
}