-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from sparrow1997/patch-1
Create stack.py #20
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#Make a class Stack | ||
class Stack: | ||
def __init__(self): | ||
self.items = [] | ||
|
||
def isEmpty(self): | ||
return self.items == [] | ||
|
||
def push(self, item): | ||
self.items.insert(0,item) | ||
|
||
def pop(self): | ||
return self.items.pop(0) | ||
|
||
def peek(self): | ||
return self.items[0] | ||
|
||
def size(self): | ||
return len(self.items) | ||
|
||
#Calling Object of class Stack | ||
s = Stack() | ||
|
||
#Calling the function | ||
s.push('hello') | ||
s.push('true') | ||
print(s.pop()) |