|
1 | | - |
| 1 | + |
2 | 2 |
|
3 | 3 | # Day 19 - Array Series Part 2 |
4 | 4 |
|
@@ -94,6 +94,43 @@ console.log (cartesian ([1, 2], [])); |
94 | 94 | console.log (cartesian ([1, 2, 3, 4], ['a', 'b', 'c'])); |
95 | 95 | ``` |
96 | 96 |
|
| 97 | +### C++ Implementation |
| 98 | + |
| 99 | +#### [Solution by @divyakhetan](./C++/CartesianProductDay19.cpp) |
| 100 | + |
| 101 | +```cpp |
| 102 | +/** |
| 103 | + * @author divyakhetan |
| 104 | + * @date 16/1/2019 |
| 105 | + */ |
| 106 | + |
| 107 | +#include<bits/stdc++.h> |
| 108 | +using namespace std; |
| 109 | + |
| 110 | +int main(){ |
| 111 | + cout << "Enter length of 1st and 2nd array"; |
| 112 | + int n1, n2; |
| 113 | + cin >> n1 >> n2; |
| 114 | + int a[n1]; |
| 115 | + int b[n2]; |
| 116 | + for(int i = 0; i < n1; i++){ |
| 117 | + cin >> a[i]; |
| 118 | + |
| 119 | + } |
| 120 | + |
| 121 | + for(int i = 0; i < n2; i++){ |
| 122 | + cin >> b[i]; |
| 123 | + } |
| 124 | + |
| 125 | + for(int i = 0; i < n1; i++){ |
| 126 | + for(int j = 0; j < n2; j++){ |
| 127 | + cout << "[ " << a[i] << " " << b[j] << " ] " << endl; |
| 128 | + } |
| 129 | + } |
| 130 | + return 0; |
| 131 | +} |
| 132 | +``` |
| 133 | + |
97 | 134 | ### Python Implementation |
98 | 135 |
|
99 | 136 | ### [Solution](./Python/cartesian_product.py) |
@@ -125,6 +162,7 @@ def main(): |
125 | 162 | set_B = get_input('B') |
126 | 163 | calculate_cartesian_product(set_A, set_B) |
127 | 164 | ``` |
| 165 | + |
128 | 166 | *** |
129 | 167 |
|
130 | 168 | ## Ques B |
@@ -172,6 +210,43 @@ function fisherYates (arr) { |
172 | 210 | fisherYates ([1, 2, 3, 4, 5, 6]); |
173 | 211 | ``` |
174 | 212 |
|
| 213 | +### C++ Implementation |
| 214 | + |
| 215 | +#### [Solution ](./C++/FisherYateShuffleDay19.cpp) |
| 216 | + |
| 217 | +```cpp |
| 218 | +/** |
| 219 | + * @author divyakhetan |
| 220 | + * @date 16/1/2019 |
| 221 | + */ |
| 222 | + |
| 223 | +#include<bits/stdc++.h> |
| 224 | +using namespace std; |
| 225 | + |
| 226 | +int main(){ |
| 227 | + cout << "Enter length of 1st and 2nd array"; |
| 228 | + int n1, n2; |
| 229 | + cin >> n1 >> n2; |
| 230 | + int a[n1]; |
| 231 | + int b[n2]; |
| 232 | + for(int i = 0; i < n1; i++){ |
| 233 | + cin >> a[i]; |
| 234 | + |
| 235 | + } |
| 236 | + |
| 237 | + for(int i = 0; i < n2; i++){ |
| 238 | + cin >> b[i]; |
| 239 | + } |
| 240 | + |
| 241 | + for(int i = 0; i < n1; i++){ |
| 242 | + for(int j = 0; j < n2; j++){ |
| 243 | + cout << "[ " << a[i] << " " << b[j] << " ] " << endl; |
| 244 | + } |
| 245 | + } |
| 246 | + return 0; |
| 247 | +} |
| 248 | +``` |
| 249 | + |
175 | 250 | ### Python implementation |
176 | 251 |
|
177 | 252 | #### [Solution](./Python/fisher_yates.py) |
|
0 commit comments