#include <iostream>
#include <vector>
// Function to clone a 2D vector
template <typename T>
std::vector<std::vector<T>> clone2DVector(const std::vector<std::vector<T>>& vector) {
std::vector<std::vector<T>> cloned(vector.size());
for (size_t i = 0; i < vector.size(); i++) {
cloned[i] = vector[i]; // Copies the inner vector
}
return cloned;
}
void PrintVector(const std::vector<std::vector<int>>& vector) { //Added & and changed the vector type
for (const auto& row : vector) {
for (int val : row) {
std::cout << val << " ";
}
std::cout << std::endl;
}
}
int main() {
// Example using std::vector
std::vector<std::vector<int>> vector = {
{1, 2, 3, 0}, {4, 5, 6, 85}, {7, 8, 9, 10}
};
std::vector<std::vector<int>> clonedVector = clone2DVector(vector);
std::cout << "Original Vector:" << std::endl;
PrintVector(vector);
std::cout << "Cloned Vector:" << std::endl;
PrintVector(vector);
return 0;
}
/*
run:
Original Vector:
1 2 3 0
4 5 6 85
7 8 9 10
Cloned Vector:
1 2 3 0
4 5 6 85
7 8 9 10
*/