-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.py
64 lines (49 loc) · 1022 Bytes
/
Stack.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Stack Implementation Using Python
#Operations :
# 1. Push()
# 2. Pop()
# 3. stack_Print()
# 4. isEmpty()
# 5.IsFull()
class stack:
Stack = []
size = 0
def __init__(self):
type(self).size = int(input("Enter The Size Of Stack : ") )
# isEmpty Method
def isEmpty(temp_stack):
if len(temp_stack.Stack) == 0:
return 1
else:
return 0
def isFull(temp_stack):
if len(temp_stack.Stack) == stack.size:
return 1
else:
return 0
def stack_Print(temp_stack):
print (temp_stack.Stack)
def pop(temp_stack):
if isEmpty(temp_stack)!=1:
return temp_stack.Stack.pop()
else :
print ("Stack Is Empty")
def push(temp_stack,val):
if isFull(temp_stack) !=1:
temp_stack.Stack.append(val)
else:
print("Stack is Full")
S = stack()
#-----------------------Test Case -----------------------
#print(len(S.Stack))
#print(len(S.Stack))
#print(S.size)
#-----------------------Test Case -----------------------
isEmpty(S)
isFull(S)
push(S,2)
push(S,4)
stack_Print(S)
pop(S)
pop(S)
stack_Print(S)