Skip to content

Commit 579bbc2

Browse files
authored
Merge pull request larymak#224 from Chrischege/test
Added a new folder 'stack'
2 parents 2a80986 + 59918d4 commit 579bbc2

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# A stack implementation in python
2+
3+
## What is a stack?
4+
5+
A stack is a collection of elements in which the most recent element can be removed
6+
It uses the LIFO(last in first out) concept.
7+
The last item to enter the stack is the first item to leave the stack.
8+
It can be modelled using a list and the main operations that can be done are POP and PUSH in this case POP and APPEND.
9+
Stacks are used in real life to build the UNDO and REDO functions where the steps of the user are stored in a stack and the last step can be retraced. like in microsoft word undo and redo function.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python 3 or a higher version
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class stack:
2+
3+
def __init__(self):
4+
self.items=input()
5+
print(self.items.lstrip)
6+
7+
def is_empty(self):
8+
return self.items==[]
9+
10+
def push(self,item):
11+
self.items.insert(0,item)
12+
13+
def pop(self):
14+
return self.items.pop(0)
15+
16+
def print_stack(self):
17+
print(self.items)
18+
19+
stack1=stack()
20+
stack1.push(5) #allows the user to add items to the stack
21+
stack1.pop() #allows one to remove items to the stack
22+
stack1.print_stack()
23+
24+
25+
26+
27+

0 commit comments

Comments
 (0)