本文整理汇总了C++中Array2D::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Array2D::push_back方法的具体用法?C++ Array2D::push_back怎么用?C++ Array2D::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array2D
的用法示例。
在下文中一共展示了Array2D::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CombinationWithDuplicatedElementsByNonRecursion
Array2D CombinationWithDuplicatedElementsByNonRecursion(Array1D array, int K)
{
Array2D result;
if (array.empty() || K <= 0) { return result; }
if (array.size() < K) {
result.push_back(array); /** @warning maybe exclude it */
return result;
}
std::sort(array.begin(), array.end());
result.push_back(Array1D());
int last = array[0], opt_result_num = 1;
for (int i = 0; i < array.size(); i++) {
if (array[i] != last) {
last = array[i];
opt_result_num = result.size();
}
Array2D::size_type result_size = result.size();
for (int j = result_size - 1; j >= result_size - opt_result_num; j--) {
result.push_back(result[j]);
result.back().push_back(array[i]);
}
}
return result;
}
示例2: SetOfStacks
Array2D SetOfStacks(Array2D ope, int size)
{
// write code here
if (ope.empty()) { return Array2D(); }
if (size <= 0) { assert(false); }
/** @brief has no bugs, but too complex. */
// stack<Array1D> temp;
// Array1D cur_array(size);
// int cur_index = -1;
// for (int i = 0; i < ope.size(); i++) {
// if (ope[i][0] == 1) {
// if (cur_index == size - 1) {
// temp.push(cur_array);
// cur_array = Array1D(size);
// cur_index = -1;
// }
// cur_array[++cur_index] = ope[i][1];
// } else if (ope[i][0] == 2) {
// if (cur_index == -1) {
// if (temp.empty()) { return Array2D(); }
// cur_array = temp.top();
// temp.pop();
// cur_index = size - 1;
// }
// cur_index--;
// } else { return Array2D(); }
// }
//
// Array2D result(temp.size() + 1);
// if (cur_index > -1) {
// result[temp.size()] = Array1D(&cur_array[0], &cur_array[cur_index] + 1);
// }
// cur_index = temp.size() - 1;
// while(!temp.empty()) {
// result[cur_index--] = temp.top();
// temp.pop();
// }
/** @todo don't pass all test cases */
Array2D result;
Array1D cur_array;
for (Array2D::iterator it = ope.begin(); it != ope.end(); ++it) {
if ((*it)[0] == 1) {
if (cur_array.size() == size) {
result.push_back(cur_array);
cur_array.clear();
}
cur_array.push_back((*it)[1]);
} else if ((*it)[0] == 2){
if (cur_array.empty()) {
if (result.empty()) { assert(false); }
cur_array = result.front();
result.pop_back();
}
cur_array.pop_back();
} else { assert(false); }
}
if (!cur_array.empty()) { result.push_back(cur_array); }
return result;
}
示例3:
static void CombinationWithDuplicatedElementsVer2Helper(Array1D &array, int left,
int k, int times,
Array1D &temp,
Array2D &result)
{
if (array.size() - left < k) { return; }
if (k == 0) {
result.push_back(temp);
return;
}
for (int i = left; i <= array.size(); i++) {
if (i == 0 || array[i] != array[i - 1]) {
times = 1;
temp.push_back(array[i]);
CombinationWithDuplicatedElementsVer2Helper(array, i + 1, k - 1, 1, temp, result);
temp.pop_back();
}
else {
times++;
if (temp.size() >= times - 1 && temp[temp.size() - times + 1] == array[i]) {
temp.push_back(array[i]);
CombinationWithDuplicatedElementsVer2Helper(array, i + 1, k - 1, times, temp, result);
temp.pop_back();
}
}
}
}
示例4: CombinationWithDuplicatedElementsHelper
static void CombinationWithDuplicatedElementsHelper(Array1D &array, int left, int k,
int times, Array1D &temp, Array2D &result)
{
assert(left >= 0);
if (array.size() - left < k) { return; }
if (k == 0) {
result.push_back(temp);
return;
}
if (left == 0 || array[left] != array[left - 1]) {
temp.push_back(array[left]);
CombinationWithDuplicatedElementsHelper(array, left + 1, k - 1, 1, temp, result);
temp.pop_back();
CombinationWithDuplicatedElementsHelper(array, left + 1, k, 1, temp, result);
}
else {
if (temp.size() >= times && temp[temp.size() - times] == array[left]) {
temp.push_back(array[left]);
CombinationWithDuplicatedElementsHelper(array, left + 1, k - 1, times + 1, temp, result);
temp.pop_back();
}
CombinationWithDuplicatedElementsHelper(array, left + 1, k, times + 1, temp, result);
}
}
示例5: PermutationUnique
/**
* @brief find all permutation of array
* @brief array has some repeating elements
*/
Array2D PermutationUnique(Array1D array)
{
Array2D result;
if (array.empty()) { return result; }
if (array.size() == 1) {
result.push_back(array);
return result;
}
PermutationUniqueHelper(array, 0, result);
return result;
}
示例6: CombinationByDecrease
Array2D CombinationByDecrease(Array1D array, int K)
{
Array2D result;
if (array.empty() || K <= 0) { return result; }
if (array.size() < K) {
result.push_back(array); /** @warning maybe exclude it */
return result;
}
Array1D temp(K);
CombinationByDecreaseHelper(array, array.size(), K, temp, result);
}
示例7: Combination
Array2D Combination(Array1D array, int K) {
Array2D result;
if (array.empty() || K <= 0) { return result; }
if (array.size() < K) {
result.push_back(array);
return result;
}
Array1D temp;
CombinationHelper(array, 0, array.size() - 1, K, temp, result);
return result;
}
示例8: PermutationHelper
static void PermutationHelper(Array1D &array, int index, Array2D &result)
{
if (index == array.size()) {
result.push_back(array);
return;
}
for (int i = index; i < array.size(); ++i) {
std::swap(array[index], array[i]);
PermutationHelper(array, index + 1, result);
std::swap(array[index], array[i]);
}
}
示例9: CombinationByNonRecursion
Array2D CombinationByNonRecursion(Array1D array, int K)
{
Array2D result;
if (array.empty() || K <= 0) { return result; }
if (array.size() < K) {
result.push_back(array); /** @warning maybe exclude it */
return result;
}
Array1D cur(1);
for (int i = 1; i <= array.size(); i++) {
Array1D::size_type size = cur.size();
Array1D temp;
/** @bug has some problems */
for (int j = 0; j < size; j++) {
temp.push_back(cur[j]);
temp.push_back(array[i]);
if (temp.size() == K) { result.push_back(temp); }
else { cur.push_back(array[i]); }
}
}
return result;
}
示例10: CombinationByBinary
Array2D CombinationByBinary(Array1D array, int K)
{
Array2D result;
if (array.empty() || K <= 0) { return result; }
if (array.size() < K) {
result.push_back(array); /** @warning maybe exclude it */
return result;
}
/** @warning sort or not */
Array1D temp;
int begin = (1 << K) - 1, end = (1 << array.size()) - (1 << (array.size() - K));
for (int bit = begin; bit <= end; bit = NextBit(bit)) {
temp.clear();
for (int i = 0; i < array.size(); i++) {
if (bit & (1 << i)) {
temp.push_back(array[i]);
}
}
result.push_back(temp);
}
return result;
}
示例11: CombinationByDecreaseHelper
static void CombinationByDecreaseHelper(Array1D &array, int left, int count,
Array1D &temp, Array2D &result)
{
for (int i = left; i >= count; i--) {
temp[count - 1] = array[i - 1];
if (count > 1) {
CombinationByDecreaseHelper(array, i - 1, count - 1, temp, result);
}
else {
result.push_back(temp);
}
}
}
示例12: CombinationByIncreaseHelper
static void CombinationByIncreaseHelper(Array1D &array, int left, int count,
Array1D &temp, Array2D &result)
{
for (int i = left; i < array.size() + 1 - count; i++) {
temp[count - 1] = array[i];
if (count - 1 == 0) {
result.push_back(temp);
}
else {
CombinationByIncreaseHelper(array, i + 1, count - 1, temp, result);
}
}
}
示例13: PermutationUniqueHelper
static void PermutationUniqueHelper(Array1D &array, int index, Array2D &result)
{
if (index == array.size()) {
result.push_back(array);
return;
}
for (int i = index; i < array.size(); i++) {
if (HasSameElement(array, index, i, array[i])) {
std::swap(array[index], array[i]);
PermutationUniqueHelper(array, index + 1, result);
std::swap(array[index], array[i]);
}
}
}
示例14: CombinationHelper
static void CombinationHelper(Array1D &array, int left, int right, int k,
Array1D &temp, Array2D &result)
{
assert(!array.empty());
assert(left >= 0 && right >= 0);
if (right - left + 1 < k) { return; }
if (k == 0) {
result.push_back(temp);
return;
}
temp.push_back(array[left]);
CombinationHelper(array, left + 1, right, k - 1, temp, result);
temp.pop_back();
CombinationHelper(array, left + 1, right, k, temp, result);
}
示例15: assert
static void CombinationVer2Helper(Array1D &array, int left, int right, int k,
Array1D &temp, Array2D &result)
{
assert(!array.empty());
assert(left >= 0 && right >= 0);
if (k == 0) {
result.push_back(temp);
return;
}
for (int i = left; i <= right - k + 1; i++) {
temp.push_back(array[i]);
CombinationVer2Helper(array, i + 1, right, k - 1, temp, result);
temp.pop_back();
}
}