Stack uses the LIFO(last-in first-out) ordering. like a stack of dinner plates.
class Node
{
public:
Node(Node *item)
{
value = item->value;
next = item ->next;
}
int value;
Node* next;
};
class Stack {
Node* top;
public:
int Pop() {
if (top != 0) {
Node* item = top;
top = top->next;
int val = item->value;
delete item;
return val;
}
}
void Push(Node *item) {
Node* t = new Node(item);
t->next = top;
top = t;
}
int peek() {
return top->value;
}
}