diff --git a/main.cpp b/main.cpp new file mode 100644 index 00000000..1b7a48e9 --- /dev/null +++ b/main.cpp @@ -0,0 +1,55 @@ +#include +#include +using namespace std; + +class ListNode { + public: + int val; + ListNode *next; + ListNode(int v) { + val=v; + next=NULL; + } +}; + +ListNode *AddNode() { + int val; + cout << "Data Element : " << endl; + cin >> val; + ListNode *newNode=new ListNode(val); + return newNode; +} + +bool isPalindrome(ListNode *first) { + ListNode *head=first; + stackst; + while(head) { + st.push(head->val); + head=head->next; + } + head=first; + while(head) { + if(st.top()!=head->val) { + return false; + } + head=head->next; + st.pop(); + } + return true; +} + +int main() { + int n; + cout << "No. of Nodes in Linked List : " << endl; + cin >> n; + ListNode *first=AddNode(); + ListNode *previous=first; + for(int i=0; inext=newNode; + previous=newNode; + } + + cout << isPalindrome(first); + return 0; +} \ No newline at end of file