|
7 | 7 | "title": "Reverse String",
|
8 | 8 | "description": "Reverses the characters in a string.",
|
9 | 9 | "code": [
|
10 |
| - "string reverseString(const string& input) {", |
11 |
| - " string reversed = input;", |
12 |
| - " reverse(reversed.begin(), reversed.end()); // Using STL's reverse function", |
| 10 | + "#include <string>", |
| 11 | + "#include <algorithm>", |
| 12 | + "", |
| 13 | + "std::string reverseString(const std::string& input) {", |
| 14 | + " std::string reversed = input;", |
| 15 | + " std::reverse(reversed.begin(), reversed.end());", |
13 | 16 | " return reversed;",
|
14 | 17 | "}"
|
15 | 18 | ],
|
|
20 | 23 | "utility"
|
21 | 24 | ],
|
22 | 25 | "author": "Vaibhav-kesarwani"
|
| 26 | + }, |
| 27 | + { |
| 28 | + "title": "Split String", |
| 29 | + "description": "Splits a string by a delimiter", |
| 30 | + "code": [ |
| 31 | + "#include <string>", |
| 32 | + "#include <vector>", |
| 33 | + "", |
| 34 | + "std::vector<std::string> split_string(std::string str, std::string delim) {", |
| 35 | + " std::vector<std::string> splits;", |
| 36 | + " int i = 0, j;", |
| 37 | + " int inc = delim.length();", |
| 38 | + " while (j != std::string::npos) {", |
| 39 | + " j = str.find(delim, i);", |
| 40 | + " splits.push_back(str.substr(i, j - i));", |
| 41 | + " i = j + inc;", |
| 42 | + " }", |
| 43 | + " return splits;", |
| 44 | + "}" |
| 45 | + ], |
| 46 | + "tags": [ |
| 47 | + "cpp", |
| 48 | + "string", |
| 49 | + "split", |
| 50 | + "utility" |
| 51 | + ], |
| 52 | + "author": "saminjay" |
23 | 53 | }
|
24 | 54 | ]
|
25 | 55 | },
|
|
0 commit comments