MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / reverseWords

Function reverseWords

String/reverseWordinString.cpp:10–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 }
9
10string reverseWords(string s) {
11 int start = 0;
12 for(int i=0;i<s.length();i++){
13 if(s[i+1] == ' ' || s[i+1]=='\0'){
14 //Since s[i+1] is space or null character, s[i] is end of a word
15 int end = i;
16 reverse(s,start,end);
17 //Since s[i+1] is space or null character, s[i+2] may be the beginning of new word
18 start = i+2;
19 }
20 }
21 reverse(s,start,s.length()-1);
22 return s;
23 }
24
25int main()
26{

Callers 1

mainFunction · 0.85

Calls 2

lengthMethod · 0.80
reverseFunction · 0.70

Tested by

no test coverage detected