c++ - what does this line means ? half += string(freq[i] / 2, i + 'a'); -
http://www.geeksforgeeks.org/print-all-palindrome-permutations-of-a-string/
what line mean
half += string(freq[i] / 2, + 'a'); in code ?
void printallpossiblepalindromes(string str) { int freq[m]; if (!ispalin(str, freq)) return; int l = str.length(); string half = ""; char oddc; (int = 0; < m; i++) { if(freq[i] % 2 == 1) oddc = + 'a'; half += string(freq[i] / 2, + 'a'); } string palin; { palin = half; if (l % 2 == 1) palin += oddc; palin += reverse(half); cout << palin << endl; } while (next_permutation(half.begin(), half.end())); }
string(freq[i] / 2, + 'a'); is coming
string (size_t n, char c); which fill constructor:
fills string n consecutive copies of character c.
so creating onstance of string class with
size_t n replaced by: freq[i] / 2 , char c i + 'a'
and string object getting concatenated object half when do:
half += string(freq[i] / 2, + 'a');
Comments
Post a Comment