Rename members of StackArray

This commit is contained in:
Shaun Reed 2020-03-23 12:46:49 +00:00
parent 44d4e2265c
commit 8af7c295c6
2 changed files with 12 additions and 12 deletions

View File

@ -14,14 +14,14 @@ class StackArray {
private: private:
enum { EMPTY=-1, MAX=10 }; enum { EMPTY=-1, MAX=10 };
class ListNode { class Node {
public: public:
ListNode() : next(NULL) {}; Node() : next(NULL) {};
ListNode(char val) : data(val), next(NULL) {}; Node(char val) : data(val), next(NULL) {};
char data; char data;
ListNode* next; Node* next;
}; };
ListNode list[MAX]; Node stack[MAX];
int top; int top;
}; };

View File

@ -4,13 +4,13 @@ void StackArray::Push(char val)
{ {
if (top < MAX && !isEmpty()) { if (top < MAX && !isEmpty()) {
this->list[++top].data = val; this->stack[++top].data = val;
} }
else if (isEmpty()) { else if (isEmpty()) {
this->list[++top].data = val; this->stack[++top].data = val;
} }
else { else {
std::cout << "Error: List is full!\n"; std::cout << "Error: stack is full!\n";
} }
return; return;
} }
@ -28,7 +28,7 @@ char StackArray::Pop()
char StackArray::Top() const char StackArray::Top() const
{ {
return this->list[top].data; return this->stack[top].data;
} }
void StackArray::Display() const void StackArray::Display() const
@ -40,8 +40,8 @@ void StackArray::Display() const
int tempTop = this->top; int tempTop = this->top;
while (tempTop >= 0) { while (tempTop >= 0) {
std::cout << "Value at list [" << tempTop << "]: " std::cout << "Value at stack [" << tempTop << "]: "
<< this->list[tempTop].data << std::endl; << this->stack[tempTop].data << std::endl;
tempTop--; tempTop--;
} }