-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
49 lines (34 loc) · 874 Bytes
/
stack.py
File metadata and controls
49 lines (34 loc) · 874 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
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 21 17:36:25 2022
@FileName: stack.py
@author: YUNJUSEOK
"""
#LIFO
class Stack:
def __init__ ( self ):
self.content = []
def __len__ ( self ):
return len( self.content );
def isEmpty( self ):
if( len( self.content ) == 0 ):
return True;
else:
return False;
def push( self, item ):
self.content.append( item );
def pop( self ):
if( self.isEmpty() ):
return False;
return self.content.pop( -1 );
def peek( self ):
if( self.isEmpty() ):
return False;
return self.content[ -1 ];
def main():
stack = Stack( );
stack.push( 1 );
print( stack.content );
print( stack.pop() );
if( __name__ == "__main__"):
main();