class Node:
  """The node in the linked list that makes up the stack."""
  def __init__(self):
    self.data = ''
    self.link = 0

class Stack:
  """A data structure in which the first element inserted is the last to be
     removed."""
  def __init__(self):
    self.top = Node()

def add(s, data):
  """Puts data onto the stack."""
  n = Node()
  n.data = data
  n.link = s.top
  s.top = n

def hasMore(s):
  """True if the stack is non-empty."""
  return s.top.link != 0

def remove(s):
  """Removes the top element from the stack."""
  n = s.top
  s.top = n.link
  return n.data

s = Stack()
add(s, "AA")
add(s, 0)
while (hasMore(s)):
  print remove(s)
