Stack

I trying to write a code for a calculator using stack is how to convert an operation from infix to postfix
her is my attempt i created a header file

#ifndef STACK_H
#define STACK_H

#include <iostream>
using namespace std;

template<class T>
struct node {
T item;
node<T>* next;
node(const T& it, node<T>* p){
// Inline function definition.
item = it;
next = p;
}
};

template<class T>
class Stack {
public:
Stack();
~Stack();
Stack(const Stack<T>& s);
Stack<T>& operator=(const Stack<T>& rhs);
bool empty() const;
void push(const T&);
T pop();
private:
node<T>* head;
void copy(const Stack<T>& s);
};


#endif // STACK_H
and this is what i attempted for the cpp file

#include <iostream>
#include "Stack.h"
using namespace std;

template <class T>
Stack<T>::Stack(){ // Default constructor
head = NULL;
}

template <class T>
bool Stack<T>::empty() const{ // empty function
return head==NULL;
}

template<class T>
Stack<T>::~Stack() { // Destructor
while (!empty()) pop();
}

template <class T>
Stack<T>::Stack(const Stack<T>& s){ // Copy constructor
head = NULL;
copy(s);
}

template <class T>
Stack<T>& Stack<T>::operator=(const Stack<T>& rhs){ // Assignment operator
if (!(this==&rhs)){
while (!empty()) pop();
copy(rhs);
}
return *this;
}
template <class T>
void Stack<T>::push(const T& Item)
{
if(IsFull())
throw FullStack();
else
{
Node* location;
location = new Node
}

}
template <class T>
T Stack<T>::pop()
{
}
template <class T>
void Stack<T>::copy(const Stack<T>& s)
{
}
i need help the write code for these function
Last edited on
You will get some help if you post your attempt :)
Topic archived. No new replies allowed.