Question: Would someone write detailed comment on following codes please I would really Appreciate it StackArray.cpp #include StackArray.h template inline StackArray ::StackArray(int maxNumber) { top =
Would someone write detailed comment on following codes please
I would really Appreciate it
StackArray.cpp
#include "StackArray.h"
template
dataItems = new DataType[maxSize]; }
template
if (other.top > -1) { dataItems = new DataType[other.maxSize]; mazSize = other.maxSize; top = other.top;
for (int i = 0; i <= top; i++) { dataItems[i] = other.dataItems[i]; } } }
template
if (other.top != -1) { dataItems = new DataType[other.maxSize]; mazSize = other.maxSize; top = other.top;
for (int i = 0; i <= top; i++) { dataItems[i] = other.dataItems[i]; } } } retrun *this; }
template
template
dataItems[++top] = newDataItem; }
template
return dataItems[top--]; }
template
dataItems = NULL; }
template
template
template
{ if (isEmpty()) { cout << "Empty stack." << endl; } else { int j; cout << "Top = " << top << endl; for (j = 0; j < maxSize; j++) cout << j << "\t"; cout << endl; for (j = 0; j <= top; j++) { if (j == top) { cout << '[' << dataItems[j] << ']' << "\t"; // Identify top } else { cout << dataItems[j] << "\t"; } } cout << endl; } cout << endl; }
template
dataItems = NULL; }
Stacklinked.cpp
#include "StackLinked.h"
template
template
template
template
template
//if (isFull()) // throw logic_error("Stack is Full. ");
try { temp = top; top = new StackNode(newDataItem, temp); } catch (...) { throw logic_error("Error allocating memory in push method. "); } }
template
if (isEmpty()) throw logic_error("Stack is Empty. ");
itemToReturn = top->dataItem; tempNode = top; top = top->next; delete tempNode;
return itemToReturn; }
template
template
template
template
// Linked list implementation. Outputs the data elements in a stack. // If the stack is empty, outputs "Empty stack". This operation is // intended for testing and debugging purposes only.
{ if (isEmpty()) { cout << "Empty stack" << endl; } else { cout << "Top\t"; for (StackNode* temp = top; temp != 0; temp = temp->next) { if (temp == top) { cout << "[" << temp->dataItem << "]\t"; } else { cout << temp->dataItem << "\t"; } } cout << "Bottom" << endl; }
}
template
delete ptr; }
template
if (ptr->next != NULL) copyHelper(ptr->next, otherNode->next); }
Again I will really Appreciate it
Thank You
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
