Implementation of Stack using Linked List Please review my code and help me to improve it. I have written this code using template. Can I use more C++11? Is using top in this code is necessary?

#include &lt;iostream&gt;


template&lt;class T&gt;
class Stack{
 struct Node{
 T data;
 Node *next;
 Node(T val):data(val),next(nullptr) {}
 };
 Node *head;
 int top;

 public:
     Stack(){
     top=-1;
     head=nullptr;
     }
    ~Stack();
     bool stack_empty();
     void push(T);
     T pop();

     void display(std::ostream&amp; out = std::cout) const
     {
       Node *node=head;
       while(node!=nullptr){
        out&lt;&lt;node-&gt;data&lt;&lt;" ";
        node=node-&gt;next;
       }
     }
};
template&lt;class T&gt;
bool Stack&lt;T&gt;::stack_empty(){
  if(top==-1)
    return true;
  else
    return false;
}

template&lt;class T&gt;
void Stack&lt;T&gt;::push(T val){

  if(top&gt;=-1){
    top++;
    Node *node=new Node(val);
    Node *tmp=head;
    if(tmp==nullptr) head=node;
    else{
        while(tmp-&gt;next!=nullptr)
            tmp=tmp-&gt;next;
        tmp-&gt;next=node;
    }
  }
  else
    std::cout&lt;&lt;"Overflow"&lt;&lt;std::endl;
}

template&lt;class T&gt;
T Stack&lt;T&gt;::pop(){
  if(stack_empty()==true)
    std::cout&lt;&lt;"Underflow"&lt;&lt;std::endl;
  else{
    top--;
    Node *node=head;
     while(node-&gt;next!=nullptr){
        node=node-&gt;next;
     }
    return node-&gt;data;
  }
}

template&lt;class U&gt;
std::ostream &amp; operator &lt;&lt;(std::ostream&amp; os, const Stack&lt;U&gt;&amp; s){
s.display(os);
return os;
}

template&lt;class T&gt;
Stack&lt;T&gt;::~Stack(){
Node *tmp=nullptr;
  while(head){
    tmp=head;
    head=head-&gt;next;
    delete tmp;
  }
  head=nullptr;
}
int main()
{
 Stack&lt;int&gt; stack1;

 stack1.push(3);
 stack1.push(4);
 stack1.push(11);
 stack1.push(30);
 std::cout&lt;&lt;stack1&lt;&lt;std::endl;
 std::cout&lt;&lt;stack1.pop()&lt;&lt;std::endl;
    return 0;
}
You leak every single node you pop. You need to delete the node.

You should add move and emplace push overloads. So that non-copyable T can be stored.

you check against "overflow" by testing top is less than -1. However signed overflow is undefined behavior and if you ever had more than 2 billion items in your stack you probably ran out of ram earlier. You can check if the stack is empty by testing if head is nullptr. So top isn't really necessary.

For every operation you seek the end of the stack, that is not necessary at all.

template&lt;class T&gt;
void Stack&lt;T&gt;::push(T val){
    top++;
    Node *node=new Node(val);
    node-&gt;next = head;
    head=node;
}

template&lt;class T&gt;
T Stack&lt;T&gt;::pop(){
  if(stack_empty()==true)
    std::cout&lt;&lt;"Underflow"&lt;&lt;std::endl;
  else{
    top--;
    Node *node=head;
    head = node-&gt;next;
    T tmp = std::move(node-&gt;data);
    delete node;
    return tmp;
  }
}