-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLStack.cpp
More file actions
58 lines (51 loc) · 767 Bytes
/
LStack.cpp
File metadata and controls
58 lines (51 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//linked stack implementation
template <typename E> class LStack: public Stack<E>
{
private:
Link<E>* top;
int size;
public:
LStack(int sz =defaultSize)
{
top = NULL;
size=sz;
}
~LStack()
{
clear();
}
void clear()
{
while (top != NULL)
{
Link<E>* temp = top;
top = top->next;
delete temp;
}
size=0;
}
void push(const E& it)
{
top = new Link<E>(it top);
size++;
}
E pop()
{
Assert(top != NULL, "stack is empty");
E it = top->element;
Link<E>* ltemp = top->next;
delete top;
top = ltemp;
size--;
return it;
}
const E& topValue() const
{
Assert(top != 0, "stack is empty");
return top->element;
}
int length() const
{
return size;
}
};