#include <bits/stdc++.h>
using namespace std;
struct StackNode {
int data;
StackNode *next;
StackNode(int a) {
data = a;
next = NULL;
}
};
class MyStack {
private:
StackNode *top;
public:
void push(int);
int pop();
MyStack() { top = NULL; }
};
//Function to push an integer into the stack.
void MyStack ::push(int x)
{
StackNode* newnode=new StackNode(x);
newnode->next=top;
top=newnode;
}
//Function to remove an item from top of the stack.
int MyStack ::pop()
{
int ddata;
if(top==NULL)
{
return -1;
}
ddata=top->data;
top=top->next;
return ddata;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter