File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ class StacksArray :
2
+
3
+ def __init__ (self ):
4
+ self ._data = []
5
+
6
+ def __len__ (self ):
7
+ return len (self ._data )
8
+
9
+ def isempty (self ):
10
+ return len (self ._data ) == 0
11
+
12
+ def push (self , e ):
13
+ self ._data .append (e )
14
+
15
+ def pop (self ):
16
+ if self .isempty ():
17
+ print ('Stack is empty' )
18
+ return
19
+ return self ._data .pop ()
20
+
21
+ def top (self ):
22
+ if self .isempty ():
23
+ print ('Stack is empty' )
24
+ return
25
+ return self ._data [- 1 ]
26
+
27
+
28
+ S = StacksArray ()
29
+ S .push (5 )
30
+ S .push (3 )
31
+ print (S ._data )
32
+ print (len (S ))
33
+ print (S .pop ())
34
+ print (S .isempty ())
35
+ print (S .pop ())
36
+ print (S .isempty ())
37
+ S .push (7 )
38
+ S .push (9 )
39
+ print (S .top ())
40
+ S .push (4 )
41
+ print (len (S ))
42
+ print (S .pop ())
43
+ S .push (6 )
44
+ S .push (8 )
45
+ print (S .pop ())
46
+
47
+
48
+
49
+
You can’t perform that action at this time.
0 commit comments