Question
Did I do this right? #include StackLinked.h template StackLinked ::StackLinked (int maxNumber) { top = NULL; } template StackLinked ::StackLinked(const StackLinked& other) { operator=(other); }
Did I do this right?
#include "StackLinked.h"
template
StackLinked
{
top = NULL;
}
template
StackLinked
{
operator=(other);
}
template
StackLinked
{
clear();
if (!other.isEmpty()) {
top = new StackNode(other.top->dataItem, 0);
StackNode *otherTemp = other.top->next;
StackNode *thisTemp = 0, *thisPrevious = top;
while (otherTemp != 0)
{
thisTemp = new StackNode(otherTemp->dataItem, 0);
thisPrevious->next = 0;
thisPrevious = top->next;
otherTemp = top;
}
}
return *this;
}
template
StackLinked
{
clear();
}
template
void StackLinked
{
if(isFull())
throw logic_error("List is Full");
StackNode *temp;
temp = new StackNode(newDataItem, top);
top = temp;
}
template
DataType StackLinked
{
if (isEmpty())
throw logic_error("Linked List is Empty.");
else {
// save the location of the top item, copy the top data item
old_top = top;
top_data = top->dataItem;
// update top
top = top->next; // works even on last node
// remove the data item from the stack
delete old_top;
old_top = NULL;
// return the data item
return top_data;
}
}
template
void StackLinked
{
this->top = NULL;
}
template
bool StackLinked
{
return (top == NULL);
}
template
bool StackLinked
{
return false;
}
template
void StackLinked
{
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;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started