File tree 2 files changed +16
-7
lines changed
2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 1
1
class queue ():
2
+ """
3
+ Queue data structure implementation using python
4
+ """
2
5
3
6
def __init__ (self ):
4
7
self .items = []
@@ -8,11 +11,12 @@ def push(self, value):
8
11
return self .items
9
12
10
13
def pop (self ):
11
- if len ( self .items ) < 1 :
12
- print ( "Queue is empty" )
14
+ if not self .items :
15
+ return None
13
16
else :
17
+ a = self .items [0 ]
14
18
del self .items [0 ]
15
- return self . items
19
+ return a
16
20
17
21
if __name__ == '__main__' :
18
22
q = queue ()
@@ -22,4 +26,5 @@ def pop(self):
22
26
print (q .pop ())
23
27
print (q .pop ())
24
28
print (q .pop ())
25
- print (q .pop ())
29
+ print (q .pop ())
30
+ print (q .items )
Original file line number Diff line number Diff line change 1
1
class stack ():
2
+ """
3
+ Stack data structure implementation using python
4
+ """
2
5
3
6
def __init__ (self ):
4
7
self .items = []
@@ -8,11 +11,12 @@ def push(self, value):
8
11
return self .items
9
12
10
13
def pop (self ):
11
- if len ( self .items ) < 1 :
12
- print ( "Stack is empty" )
14
+ if not self .items :
15
+ return None
13
16
else :
17
+ a = self .items [len (self .items ) - 1 ]
14
18
self .items .pop ()
15
- return self . items
19
+ return a
16
20
17
21
if __name__ == '__main__' :
18
22
st = stack ()
You can’t perform that action at this time.
0 commit comments