⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.23.cpp

📁 严蔚敏数据结构习题C++实现
💻 CPP
字号:
#include <iostream>
using namespace std;
#define NodeSize 1
typedef struct Node
{
    char ch;
    Node* next;
}Node;
typedef struct LString
{
    Node* head;
    Node* tail;
    int Length;
    friend istream& operator>>(istream& in,LString& s)
    {
        Node* temp = s.head;
        char flag;
        while(in)
        {
            flag = getchar();
            if(flag == ' ')
                 return in;
            temp->ch = flag;
            s.tail = temp;
            temp = temp->next = new Node();
            temp->next = NULL;
            s.Length++;
        }
    };
    friend ostream& operator<<(ostream& out,LString& s)
    {
        Node* temp = s.head;
        while(temp->next != NULL)
        {
             out << temp->ch;
             temp = temp->next;
        }
        return out;
    };
}LString;
void init_lstring(LString& s);
bool is_Palindrome(const LString s);
int main()
{
    LString s;
    init_lstring(s);
    cin >> s;
    if(is_Palindrome(s))
        cout << "YES";
    else
        cout << "NO";
    system("pause");
    return 0; 
}
void init_lstring(LString& s)
{
     s.head = s.tail = new Node();
     s.Length = 0;
}
bool is_Palindrome(const LString s)
{
     bool mark = true;
     char* array = new char[s.Length/2];
     Node* temp = s.head;
     for(int i=1; i<=s.Length/2; i++)
     {
         array[i-1] = temp->ch;
         temp = temp->next;
     }
     if(s.Length%2 == 1)
         temp = temp->next;
     for(int i=s.Length/2; i>=1; i--)
     {
         if(temp->ch != array[i-1])
         {
             mark = false;
             return false;
         }
         temp = temp->next;
     }
     return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -