【发布时间】:2013-03-18 06:08:05
【问题描述】:
这是一个家庭作业,我真的不知道该怎么做。我通常会创建 v3 = v1,然后通过 v2、通过 i 递增,并检查 v2 的元素是否在 v3 中。如果没有,我会将它们添加到 v3。但是我无法在方法之外创建 v3,如果我尝试在方法内部创建它,它只会自行重置。谁能帮帮我?
这是迄今为止我为它们提供的代码及其包装函数(它只是骨架):
// returns a new vector; every element in v1 and every element in v2 are also in this new vector
// if an element appears in both v1 and v2, it is only added once to the new vector
template <typename T> vector<T> vec_union(vector<T> &v1, vector<T> &v2)
{
return v1;
}
template <typename T> vector<T> vec_union(vector<T> &v1, vector<T> &v2, unsigned i)
{
return v1;
}
// returns a new vector; every element that is in both v1 and v2 are also in this new vector
// there are no duplicates in v1 and v2
template <typename T> vector<T> intersection(vector<T> v1, vector<T> v2)
{
return v1;
}
template <typename T> vector<T> intersection(vector<T> v1, vector<T> v2, unsigned i)
{
return v1;
}
// returns a new vector; every element that is in v1 but not v2 are also in this new vector
// there are no duplicates in v1 and v2
template <typename T> vector<T> difference(vector<T> v1, vector<T> v2)
{
return v1;
}
template <typename T> vector<T> difference(vector<T> v1, vector<T> v2, unsigned i)
{
return v1;
}
【问题讨论】:
-
那么,问题是什么?
-
@Jaysen Stoudt 你没有发布你的整个代码。我们只有包装器。请编辑您的问题,以便我们回答。
-
@jrd1 我的问题是如何实现它,因为我无法在方法之外创建 v3 并且我不知道如何在方法内部创建它?
-
您需要我们为所有功能编写正文???
-
@Zadirion 每对中的第一个是包装器,第二个是方法,我不知道从哪里开始,因为我不知道如何在其中创建 v3。
标签: c++ recursion set-theory