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