DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Is The List Palindrome?

`#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    list<int> lst;
    int val;
    while (cin >> val && val != -1)
    {
        lst.push_back(val);
    }
    int f = 0;
    for (int i = lst.front(), j = lst.back(); i < j; i++, j--)
    {
        if (i != j)
        {
            f = 1;
            break;
        }
    }
    if (f)
    {
        cout << "NO\n";
    }
    else
        cout << "YES\n";
}`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)