| 35 | // Copy constructor |
| 36 | template <typename T> |
| 37 | Stack<T>::Stack(const Stack& stack) |
| 38 | { |
| 39 | if (stack.m_head) |
| 40 | { |
| 41 | m_head = new Node {*stack.m_head}; // Copy the top node of the original |
| 42 | Node* oldNode {stack.m_head}; // Points to the top node of the original |
| 43 | Node* newNode {m_head}; // Points to the node in the new stack |
| 44 | |
| 45 | while (oldNode = oldNode->m_next) // If m_next was nullptr, the last node was copied |
| 46 | { |
| 47 | newNode->m_next = new Node{*oldNode}; // Duplicate it |
| 48 | newNode = newNode->m_next; // Move to the node just created |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Destructor |
| 54 | template <typename T> |
nothing calls this directly
no outgoing calls
no test coverage detected