import sys
STACK_SIZE=100
contents=[None]*STACK_SIZE
top=0
def terminate(message):
print message
sys.exit()
def make_empty():
top=0
def is_empty():
if(top==0):
return True
else:
return False
def is_full():
if(top==STACK_SIZE):
return True
else:
return False
def push(i):
if(is_full()):
terminate("Error in push: stack is full.")
contents[top+1]=i
def pop():
if(is_empty()):
terminate("Error in push: stack is empty.")
return contents[top-1]
import sys
STACK_SIZE=100
contents=[None]*STACK_SIZE
top=0
def terminate(message):
print message
sys.exit()
def make_empty():
top=0
def is_empty():
if(top==0):
return True
else:
return False
def is_full():
if(top==STACK_SIZE):
return True
else:
return False
def push(i):
if(is_full()):
terminate("Error in push: stack is full.")
contents[top+1]=i
def pop():
if(is_empty()):
terminate("Error in push: stack is empty.")
return contents[top-1]
class Stack:
def __init__(self):
self.items = []
def is_empty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def size(self):
return len(self.items)
def make_empty(self):
while len(self.items) > 0 : self.items.pop()
s1=Stack()
s2=Stack()
s1.push(1)
s1.push(2)
n=s1.pop()
print "Popped %d from s1"%n
s2.push(n)
n=s1.pop()
print "Popped %d from s1"%n
s2.push(n)
while(s2.is_empty()!=True):
print "Popped %d from s2"%s2.pop()
s2.push(3)
s2.make_empty()
if(s2.is_empty()):
print "s2 is empty"
else:
print "s2 is not empty"
import sys
STACK_SIZE=100
contents=[None]*STACK_SIZE
top=0
def terminate(message):
print message
sys.exit()
def make_empty():
top=0
def is_empty():
if(top==0):
return True
else:
return False
def is_full():
if(top==STACK_SIZE):
return True
else:
return False
def push(i):
if(is_full()):
terminate("Error in push: stack is full.")
contents[top+1]=i
def pop():
if(is_empty()):
terminate("Error in push: stack is empty.")
return contents[top-1]
#similar as above since Python doesn't have pointers
import sys
STACK_SIZE=100
contents=[None]*STACK_SIZE
top=0
def terminate(message):
print message
sys.exit()
def make_empty():
top=0
def is_empty():
if(top==0):
return True
else:
return False
def is_full():
if(top==STACK_SIZE):
return True
else:
return False
def push(i):
if(is_full()):
terminate("Error in push: stack is full.")
contents[top+1]=i
def pop():
if(is_empty()):
terminate("Error in push: stack is empty.")
return contents[top-1]
#similar as above since Python doesn't have pointers
import sys
STACK_SIZE=100
contents=[None]*STACK_SIZE
top=0
def terminate(message):
print message
sys.exit()
def make_empty():
top=0
def is_empty():
if(top==0):
return True
else:
return False
def is_full():
if(top==STACK_SIZE):
return True
else:
return False
def push(i):
if(is_full()):
terminate("Error in push: stack is full.")
contents[top+1]=i
def pop():
if(is_empty()):
terminate("Error in push: stack is empty.")
return contents[top-1]