Please review my code and let me know how I can possibly improve it.#include<iostream>using namespace std;class node{    private:                    int data;    public:                  node *next;                    node(int element)                    {                            data=element;                            next=NULL;                    }                    int getdata()                    {                        return(data);                    }                               };class stack{    private:                    node *start;    public:                    void push(int element);                    int pop();                    void traverse();                    stack()                    {                        start=NULL;                    }};inline void stack::push(int element){    node *ptr;    node *temp=start;    ptr=new node(element);    if(start==NULL)    {        start=ptr;        ptr->next=NULL;    }    else    {            while(temp->next!=NULL)            {                temp=temp->next;                }            temp->next=ptr;            ptr->next=NULL;     }}inline int stack::pop(){    node *temp=start;    node *top=start;    while(temp->next!=NULL)    {        temp=temp->next;    }    while(top->next!=temp)    {        top=top->next;    }    top->next=NULL;    int item=temp->getdata();    delete (temp);}inline void stack::traverse(){    node *temp=start;    while(temp!=NULL)    {        cout<<data is<<temp->getdata();        temp=temp->next;    }}int main(){    stack a;    for(int i=0;i<10;i++)    {        a.push(i);    }    a.traverse();    for(int i=0;i<5;i++)    {        a.pop();    }    a.traverse();    return(0);}
Implementation of stack using pointers
c++;beginner;stack;collections;pointers
First of all, I will start with one of the most common remarks: please, do not use using namespace std;. It is especially bad if you write it in a header file since it leads to namespace pollution and name clashes.Instead of a method named traverse, it would be better to overload operator<< to print your list. Here is how you could adapt your function (put that code in your class):friend std::ostream& operator<<(std::ostream& stream, const stack& sta){    node *temp= sta.start;    while(temp!=NULL)    {        stream<<data is<<temp->getdata();        temp=temp->next;    }    return stream;}Don't forget to make it a friend function so that it can access the private members of stack.Generally speaking, you shouldn't mark your functions inline. While it may sometimes speed up your code for small functions (your functions aren't small), most of the time, it will simply be totally ignored by the compiler. Even if it is taken into account by the compiler for inlining, it could still make your executable larger and will probably not significantly speed up your code. Worse: since inline functions have to live in the header file, you will have to compile again every file including this one when you change the implementation of your functions. Bottom line: remove all your inline qualifications, they won't gain you anything and may make things worse.From the implementation of pop, I bet that it is meant to return the popped int since you called getdata. However, you forgot to return item. Your compiler should have warned you about the unused variable item and the non-void function pop returning nothing. If not, you should tell your compiler to give you more warnings.You don't need to write return 0; at the end of the function main in C++. If nothing has been returned when the end of the function is reached, it automagically does return 0;. This remark only holds for the function main though. Also, you don't need to put parenthesis around the returned result; return is not a function.