The required files are missing in the question – class StackEmpty, SLinkedList<> and also the current implementation of LinkedStack.cpp which needs to be converted.
I have tried to answer assuming there are following methods in SLinkedList
get(int index) – to get an element at given index position in the list
add(const Elem &e) – add an element to end fo list
remove(int index) – remove an elelment at specified index
Let me know if you need more help, but I will need the existing implementation. If you already have the methods implemented, please copy and paste your code inside the corresponding functions.
template <typename Elem>
class LinkedStack{
public:
LinkedStack();
int size() const;
bool empty() const;
const Elem& top() const throw(StackEmpty);
void push(const Elem& e);
void pop() throw(StackEmpty);
private:
SLinkedList<Elem> S;
int n;
};
template <typename Elem>
LinkedStack<Elem>::LinkedStack()
{
n = 0;
}
template <typename Elem>
int LinkedStack<Elem>::size(){
return n;
}
template <typename Elem>
bool LinkedStack<ELem>::empty(){
return n == 0;
}
template <typename Elem>
const Elem& LinkedStack<Elem>::top() const throw (StackEmpty)
{
if(empty())
throw StackEmpty();
return S.get(n-1);
}
template <typename Elem>
void LinkedStack<Elem>::push(<#const Elem &e#>)
{
S.add(e);
n++;
}
template <typename Elem>
void LinkedStack<Elem>::pop() throw (StackEmpty)
{
if(empty())
throw StackEmpty();
S.remove(n-1);
n–;
}