我有一项任务,所以我并不是真的想找人来解决它,我只是想了解实际要求的是什么,因为我觉得它的措辞很糟糕。
1. Please implement the function described in the comment of this incomplete code snippet
// AudioEffect is the base class for effects that can process
// audio and have a subsequent effect (next).
struct AudioEffect {
virtual ~AudioEffect() = default;
virtual void process(float* buf, size_t num) = 0;
std::shared_ptr<AudioEffect> next;
};
// Implement a function that checks if there is a feedback loop
// in the effects chain.
... detect_feedback(...)
{
}发布于 2019-07-11 20:28:09
我能看到的唯一的循环是在指针链中。
因此,您必须遵循next指针,并确保您永远不会两次遇到相同的效果。
发布于 2019-07-11 20:43:54
你要检查给定的图是否是循环的。
函数参数应该是std::shared_ptr<AudioEffect>对象的容器。返回布尔值。
对于容器中的每个元素,使用BFS或DFS遍历图形。每个节点需要组合一个indicator,该indicator最初为0,访问后变为1。程序应该在访问节点之前检查指示器。如果它是1,则该图是循环的。您可以抛出异常或中断循环以退出搜索。
你必须学习数据结构和算法。勇敢点儿!
发布于 2019-07-14 07:24:41
您应该创建一个效果的链接列表,然后遍历该列表并检查每个共享指针的use_count。如果大于2,则存在反馈。
https://stackoverflow.com/questions/56988854
复制相似问题