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);
}