问题描述
struct Node {
int data;
Node* next;
Node* prev;
Node() : data(0),next(nullptr),prev(nullptr) { }
explicit Node(int elt) : data(elt),prev(nullptr) { }
};
class DequeEmptyException { };
class Deque {
public:
Deque();
~Deque();
Deque(const Deque& orig);
Deque& operator=(const Deque& rhs);
private:
Node* head;
Node* tail;
int length;
void copy(const Deque& source,Deque& destination);
};
这是我从源到目标的复制构造函数。
void Deque::copy(const Deque& source,Deque& destination) {
// create dummy header
destination.head = new Node;
destination.head->next = destination.head->prev = destination.head;
// copy nodes
for (Node *p = source.head->next; p != source.head; p = p->next) {
Node *t = new Node;
t->data = p->data;
// insert at end of list
t->next = destination.head;
t->prev = destination.head->prev;
t->prev->next = t;
t->next->prev = t;
}
source.length = destination.length;
}
这是我的尝试。它看起来是否正确,因为 Deque 中还有许多我无法展示的其他实现。这是最令人困惑的。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)