source: palindrome.hpp @ f6c467d

Last change on this file since f6c467d was f6c467d, checked in by Agnibho Mondal <mail@…>, 4 years ago

Rewritten in C++

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**********************************************************************
2 * Title: Anagram
3 * Description: Application for finding anagrams of a word
4 * Author: Agnibho Mondal
5 * Website: http://code.agnibho.com/anagram
6 **********************************************************************
7   Copyright (c) 2013-2015 Agnibho Mondal
8   All rights reserved
9 **********************************************************************
10   This file is part of Anagram.
11   
12   Anagram is free software: you can redistribute it and/or modify
13   it under the terms of the GNU General Public License as published by
14   the Free Software Foundation, either version 3 of the License, or
15   (at your option) any later version.
16   
17   Anagram is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   GNU General Public License for more details.
21   
22   You should have received a copy of the GNU General Public License
23   along with Anagram.  If not, see <http://www.gnu.org/licenses/>.
24 **********************************************************************/
25#ifndef PALINDROME
26#define PALINDROME
27
28/*
29 * Provides a function for checking if a word is a palindrome
30 */
31
32#include <string> //For string
33#include <algorithm> //For reverse
34
35bool is_palindrome(std::string word){ //Checks if the provided word is a plindrome.
36  std::string rev=word; //Copy the string
37  std::reverse(rev.begin(), rev.end()); //Reverse the copied string
38  if(word.compare(rev)==0){ //True if string compare returns 0 i.e. both strings are equal.
39    return true;
40  }
41  else{ //False if string compare returns non-zero i.e. strings are unequal.
42    return false;
43  }
44}
45
46#endif //PALINDROME
Note: See TracBrowser for help on using the repository browser.