17-4 50%
17-4 50%
#ifndef H_StackType
#define H_StackType
#include <iostream>
#include <cassert>
#include "stackADT.h"
void initializeStack();
//Function to initialize the stack to an empty state.
//Postcondition: The stack elements are removed;
// stackTop = nullptr;
void pop();
//Function to remove the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: The stack is changed and the top
// element is removed from the stack.
linkedStackType();
//Default constructor
//Postcondition: stackTop = nullptr;
~linkedStackType();
//Destructor
//Postcondition: All the elements of the stack are
// removed from the stack.
private:
nodeType<Type> *stackTop; //pointer to the stack
//Default constructor
template <class Type>
linkedStackType<Type>::linkedStackType()
{
stackTop = nullptr;
}
if (stackTop != nullptr)
{
temp = stackTop; //set temp to point to the top node
if (otherStack.stackTop == nullptr)
stackTop = nullptr;
else
{
current = otherStack.stackTop; //set current to point
//to the stack to be copied
newNode->info = current->info;
newNode->link = NULL;
last->link = newNode;
last = newNode;
current = current->link;
}//end while
}//end else
}
//copy constructor
template <class Type>
linkedStackType<Type>::linkedStackType(
const linkedStackType<Type>& otherStack)
{
stackTop = nullptr;
copyStack(otherStack);
}//end copy constructor
//destructor
template <class Type>
linkedStackType<Type>::~linkedStackType()
{
initializeStack();
}//end destructor
return *this;
}//end operator=
#endif