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:
enum { EMPTY=-1, MAX=10 };
class ListNode {
class Node {
public:
ListNode() : next(NULL) {};
ListNode(char val) : data(val), next(NULL) {};
Node() : next(NULL) {};
Node(char val) : data(val), next(NULL) {};
char data;
ListNode* next;
Node* next;
};
ListNode list[MAX];
Node stack[MAX];
int top;
};

View File

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