📄 stack.cpp
字号:
#include "../../4/LINKSTAC/STACK1.CPP"
Stack::Stack(const Stack &original) // copy constructor
/*
Post: The Stack is initialized as a copy of Stack original.
*/
{
Node *new_copy, *original_node = original.top_node;
if (original_node == NULL) top_node = NULL;
else { // Duplicate the linked nodes.
top_node = new_copy = new Node(original_node->entry);
while (original_node->next != NULL) {
original_node = original_node->next;
new_copy->next = new Node(original_node->entry);
new_copy = new_copy->next;
}
}
}
void Stack::operator = (const Stack &original) // Overload assignment
/*
Post: The Stack is reset as a copy of Stack original.
*/
{
Node *new_top, *new_copy, *original_node = original.top_node;
if (original_node == NULL) new_top = NULL;
else { // Duplicate the linked nodes
new_copy = new_top = new Node(original_node->entry);
while (original_node->next != NULL) {
original_node = original_node->next;
new_copy->next = new Node(original_node->entry);
new_copy = new_copy->next;
}
}
while (!empty()) // Clean out old Stack entries
pop();
top_node = new_top; // and replace them with new entries.
}
Stack::~Stack() // Destructor
/*
Post: The Stack is cleared.
*/
{
while (!empty())
pop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -