You are on page 1of 1

1

def push(contents):
if len(stack) >= limit:

print 'Stack Overflow!'

else:

stack.append(contents)

5
6

print 'Stack after Push',stack


def pop():

if len(stack) <= 0:

print 'Stack Underflow!'

return 0
else:

1
0
11
1
2
1
3
1
4
1
5
1
6

return stack.pop()
stack = []
top,traversal,contents = -1,0,0
limit = input('Enter the no of elements to be stored in
stack:')
for traversal in range(limit):
contents = input('Enter element '+str(traversal)+':')
push(contents)
traversal = 0
for traversal in range(limit):
print 'Popping '+str(limit-traversal)+'th
element:',pop()
print 'Stack after Popping!',stack

1
7
1
8
1
9
2
0
2
1
2
2
In C++:

You might also like