]> Softwares of Agnibho - anagram.git/blob - check.hpp
Removed binaries
[anagram.git] / check.hpp
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 CHECK
26 #define CHECK
27
28 /*
29 * Provides a function for checking if two words are anagrams of each other.
30 */
31
32 #include <string> //For string
33 #include <algorithm> //For sort
34
35 bool is_anagram(std::string str_1, std::string str_2){ //Compares two strings to check if they are anagrams.
36 str_1.erase(remove_if(str_1.begin(), str_1.end(), ::isspace), str_1.end()); //Remove spaces from first string
37 str_2.erase(remove_if(str_2.begin(), str_2.end(), ::isspace), str_2.end()); //Remove spaces from second string
38 std::sort(str_1.begin(), str_1.end()); //Sort first string
39 std::sort(str_2.begin(), str_2.end()); //Sort second string
40 if(str_1.compare(str_2)==0){ //If comparison returns 0 i.e. sorted strings are equal, return true.
41 return true;
42 }
43 else{ //If sorted strings are not equal return false.
44 return false;
45 }
46 }
47
48 #endif //CHECK