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