#pragma once
#include <iostream>
using namespace std;
class Link {
public:
int element;
Link *next;
Link(const int &elemval, Link* nextval) {
element = elemval;
next = nextval;
}
Link(Link* nextval) {
next = nextval;
}
Link() {
next = NULL;
}
};
#pragma once
#include <iostream>
#include "Link.h"
using namespace std;
class LStack
{
private:
Link* top;
int size;
public:
LStack()
{
size = 0;
top = NULL;
}
~LStack() { clear(); }
void clear()
{
while (top != NULL)
{
Link* temp = top;
top = top->next;
delete temp;
}
size = 0;
}
void push(const int& it)
{
top = new Link(it, top);
size++;
}
int pop()
{
int it = top->element;
Link* temp = top->next;
delete top;
top = temp;
size--;
return it;
}
int topValue()const
{
return top->element;
}
int length()const
{
return size;
}
};