From 8af7c295c69b292922b22793722ed4b14031bb46 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Mon, 23 Mar 2020 12:46:49 +0000 Subject: [PATCH] Rename members of StackArray --- plates/cpp-datastruct/include/lib-datastruct.h | 10 +++++----- plates/cpp-datastruct/src/lib-datastruct.cpp | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plates/cpp-datastruct/include/lib-datastruct.h b/plates/cpp-datastruct/include/lib-datastruct.h index 2090fee..b9c4772 100644 --- a/plates/cpp-datastruct/include/lib-datastruct.h +++ b/plates/cpp-datastruct/include/lib-datastruct.h @@ -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; }; diff --git a/plates/cpp-datastruct/src/lib-datastruct.cpp b/plates/cpp-datastruct/src/lib-datastruct.cpp index 3f32229..f52cc0b 100644 --- a/plates/cpp-datastruct/src/lib-datastruct.cpp +++ b/plates/cpp-datastruct/src/lib-datastruct.cpp @@ -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--; }