Binary Search Tree (C++)
Loading...
Searching...
No Matches
Stack.cpp
Go to the documentation of this file.
1
14
15#include "Stack.h"
16#include <iostream>
17
22 // Remove all nodes from top to bottom.
23 while (!isEmpty()) {
24 pop();
25 }
26}
27
31void Stack::push(Node* n) {
32 StackNode* s = new StackNode(n);
33 s->next = top;
34 top = s;
35}
36
41 if (!top) return nullptr;
42 StackNode* temp = top;
43 Node* result = temp->data;
44 top = top->next;
45 delete temp;
46 return result;
47}
48
52bool Stack::isEmpty() const {
53 return top == nullptr;
54}
Declaration of the Stack class.
Represents a node within a binary search tree.
Definition Node.h:35
~Stack()
Destroys the Stack.
Definition Stack.cpp:21
Node * pop()
Removes and returns the node at the top of the stack.
Definition Stack.cpp:40
bool isEmpty() const
Checks whether the stack is empty.
Definition Stack.cpp:52
void push(Node *n)
Pushes a node onto the stack.
Definition Stack.cpp:31
Internal node type used by the Stack class.
Definition Stack.h:54