-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCppProduct.cpp
More file actions
40 lines (35 loc) · 1.08 KB
/
CppProduct.cpp
File metadata and controls
40 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Created by Clytie on 2018/3/2.
//
#include "CppProduct.h"
#include <iostream>
using namespace std;
vector<int> mproduct::CppProduct::product(const vector<vector<int> > & params) {
switch (state) {
case 0:
productVec();
for (l = 0; l < result.size(); ++l) {
state = 1;
return result[l];
case 1: ;
}
}
}
void mproduct::CppProduct::productVec() {
vector<vector<int> >().swap(result); //需要先clear,再resize,clear只会清除元素,并不会使得元素内存变为0,而swap可以清除掉内存
result.resize(1);
for (int i = 0; i < params.size(); ++i) {
vector<vector<int> > TMPresult;
for (int j = 0; j < result.size(); ++j) {
for (int k = 0; k < params[i].size(); ++k) {
vector<int> resultJ = result[j];
resultJ.push_back(params[i][k]);
TMPresult.push_back(resultJ);
}
}
result.swap(TMPresult);
}
}
vector<int> mproduct::CppProduct::product() {
return product(params);
}