小编jwi*_*son的帖子

C ++递归迭代

下午好,我希望这里的人可以帮助我了解我所缺少的东西。我自由地承认这是一项家庭作业,但是我们被允许在代码上进行协作,因此希望这里有人愿意帮忙。

对于此程序,我需要使用递归和迭代来旋转C ++中的三个项目。我的递归案例没有任何问题,但迭代版本给我带来了很多麻烦。我尝试过的所有操作都会产生段错误或无限打印。这是代码,再次感谢您的帮助:

template<typename A, typename B, typename C>
class Triple{
public:
    A first;
    B second;
    C third;

Triple(A a, B b, C c){ first = a; second = b; third = c;}

A fst(){return first;}
B snd(){return second;}
C thd(){return third;}

// The function change1(), changes the first component of a triple. 
void change1(A a){ first = a;}
};

// A linked list of triples where the order of the triple rotates as it goes.
template<typename A, typename B, …
Run Code Online (Sandbox Code Playgroud)

c++ iteration recursion

5
推荐指数
1
解决办法
399
查看次数

标签 统计

c++ ×1

iteration ×1

recursion ×1