Skip to content

Commit 4d63233

Browse files
committed
Polish up all C++ translations
1 parent 154a96b commit 4d63233

36 files changed

+149
-146
lines changed

src/code/cpp/array/sliding_window.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ int fn(vector<int>& arr) {
1111

1212
for (int right = 0; right < n; right++) {
1313
// TODO: add arr[right] to window
14-
window += arr[right];
1514

1615
while (WINDOW_CONDITION_BROKEN) {
1716
// TODO: remove arr[left] from window
18-
window -= arr[left];
19-
left += 1;
17+
left++;
2018
}
2119

2220
// TODO: update ans

src/code/cpp/array/two_pointers_one_input.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int fn(vector<int>& arr) {
1111
while (left < right) {
1212
// TODO: logic with left and right
1313
if (CONDITION) {
14-
left += 1;
14+
left++;
1515
} else {
16-
right -= 1;
16+
right--;
1717
}
1818
}
1919

src/code/cpp/array/two_pointers_two_inputs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ int fn(vector<int>& arr1, vector<int>& arr2) {
1111
while (i < arr1.size() && j < arr2.size()) {
1212
// TODO: logic
1313
if (CONDITION) {
14-
i += 1;
14+
i++;
1515
} else {
16-
j += 1;
16+
j++;
1717
}
1818
}
1919

2020
while (i < arr1.size()) {
2121
// TODO: logic
22-
i += 1;
22+
i++;
2323
}
2424

2525
while (j < arr2.size()) {
2626
// TODO: logic
27-
j += 1;
27+
j++;
2828
}
2929

3030
return ans;

src/code/cpp/backtracking/backtracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int backtrack(int curr, OTHER_ARGUMENTS...) {
1+
int backtrack(STATE curr, OTHER_ARGUMENTS...) {
22
if (BASE_CASE) {
33
// TODO: modify answer
44
return 0;

src/code/cpp/binary_search/binary_search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int fn(vector<int>& arr, int target) {
1212

1313
if (arr[mid] == target) {
1414
// TODO: logic
15-
return;
15+
return mid;
1616
}
1717
if (arr[mid] > target) {
1818
right = mid - 1;

src/code/cpp/bit_manipulation/swap_variables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <tuple>
2+
23
using namespace std;
34

45

src/code/cpp/data_structures/array.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ using namespace std;
55

66

77
template<typename T>
8-
98
class Array {
109
private:
1110
T* data;
@@ -50,13 +49,3 @@ class Array {
5049
return os;
5150
}
5251
};
53-
54-
int main() {
55-
Array<int> arr(5);
56-
for (size_t i = 0; i < arr.len(); ++i) {
57-
arr[i] = i * 10;
58-
}
59-
std::cout << "Array: " << arr << std::endl;
60-
61-
return 0;
62-
}

src/code/cpp/data_structures/binary_search_tree.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ class BinarySearchTree {
5151
return result;
5252
}
5353
};
54-

src/code/cpp/data_structures/doubly_linked_list.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DoublyLinkedList {
3030
}
3131

3232
auto curr = head;
33+
3334
while (curr->next) {
3435
curr = curr->next;
3536
}
@@ -53,13 +54,16 @@ class DoublyLinkedList {
5354
}
5455

5556
auto curr = head;
57+
5658
while (curr) {
5759
if (curr->data == data) {
5860
auto prev_node = curr->prev;
5961
prev_node->next = curr->next;
62+
6063
if (curr->next) {
6164
curr->next->prev = prev_node;
6265
}
66+
6367
return;
6468
}
6569
curr = curr->next;
@@ -91,9 +95,11 @@ class DoublyLinkedList {
9195

9296
while (curr) {
9397
result += "[" + to_string(curr->data) + "]";
98+
9499
if (curr->next) {
95100
result += " <-> ";
96101
}
102+
97103
curr = curr->next;
98104
}
99105

src/code/cpp/data_structures/graph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ class Graph {
3232

3333
string toString() {
3434
string output;
35+
3536
for (const auto& [vertex, neighbors] : graph) {
3637
output += vertex + " - ";
38+
3739
for (const auto& neighbor : neighbors) {
3840
output += neighbor + " - ";
3941
}
42+
4043
output.pop_back();
4144
output.pop_back();
4245
output += "\n";
4346
}
47+
4448
return output;
4549
}
4650
};

0 commit comments

Comments
 (0)