Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Steck {
- char data;
- Steck* next;
- }*current;
- void removeword()
- {
- while (current)
- {
- Steck* p = current;
- current = current->next;
- delete p;
- }
- }
- void addWord()
- {
- string word;
- cout << "Enter word: ";
- cin >> word;
- removeword();
- if (word.length() > 0)
- {
- for (int i = word.length(); i >= 0; i--)
- {
- Steck* p = current;
- current = new Steck;
- current->data = word[i];
- current->next = p;
- }
- }
- else { cout << "No word"; }
- }
- void printwords()
- {
- Steck* p = current;
- while (p->next)
- {
- cout << p->data;
- p = p->next;
- }
- cout << "" << endl;
- }
- bool checkForPalyndrom()
- {
- string word = "";
- Steck* p = current;
- while (p->next)
- {
- word += p->data;
- p = p->next;
- }
- for (int i = 0; i < word.length(); i++)
- {
- if (word[i] != word[word.length() - i - 1])
- {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- short choice;
- do
- {
- cout << "[1] Add word\n[2] Remove word \n[3] Print words\n[4] Check for palyndrom\n[0] Exit\n";
- cin >> choice;
- switch (choice)
- {
- case 1:
- system("cls");
- addWord();
- choice = -1;
- break;
- case 2:
- system("cls");
- if (!current) {
- cout << "No words to remove\n";
- }
- else {
- removeword();
- }
- choice = -1;
- break;
- case 3:
- system("cls");
- if (!current) {
- cout << "No elements to print\n";
- }
- else {
- printwords();
- }
- choice = -1;
- break;
- case 4:
- system("cls");
- if (!current) {
- cout << "no word for check\n";
- }
- else {
- if (checkForPalyndrom())
- {
- cout << "Word is palyndrom\n";
- }
- else
- {
- cout << "Word is not palyndrom\n";
- }
- }
- choice = -1;
- break;
- default:
- break;
- }
- } while (choice < 0 || choice > 4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement