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 from __future__ import print_function
26 import os, sys, re
28 """ Basic stack class """
31
32
33 - def push(self,item):
34 """ method for pushing an item on a stack """
35 self.__items.append(item)
36
38 """ method for popping an item from a stack """
39 v = self.__items.pop()
40 return v
41
43 """ method to check whether the stack is empty or not """
44 return (self.__items == [])
45
47 """ return the contents of the stack as a single text block. """
48 return "\n".join(self.__items)
49
50
51 pstack = Stack()
53 pstack.push("A")
54 pstack.push("B")
55
56 pstack.push("C1")
57 pstack.pop()
58
59 pstack.push("C2")
60 pstack.push("D2")
61 pstack.pop()
62 pstack.pop()
63
64 print(pstack.contents())
65
66
67
68 if ( __name__ == '__main__'): main()
69