title: Implementing Stacks and Queues using a Linked List
body: <p>I'm trying to go over some previous homework problems in my computer science class with regards to Linked List. This question is really bothering me on how I should go about this, where it wants me to implement a "Stack" and a "Queue" class to go along using my Linked List class I made a while back. That is all the question states, so would I have to use my ListNode class which is this.</p>
  
  <pre><code>class ListNode(object):
  
      def __init__(self, item = None, link = None):
  
          '''creates a ListNode with the specified data value and link
          post: creates a ListNode with the specified data value and link'''
  
          self.item = item
          self.link = link
  </code></pre>
  
  <p>How would I go about making a stack class that can push and pop? Would my code look like this or will I be way off?</p>
  
  <pre><code>from ListNode import ListNode
  
  class LinkedStack(object):
      def __init__(self, ListNode.item):
          stack = []
      def push(self,item):
          self.append(ListNode.item)
          self.size += 1
      def isEmpty(self):
          return not self
  </code></pre>
  
  <p>I just based that code off examples I have seen on this web page. Any help to make a simple stack class based off a linked list? For some reason it wants me to test my code using this class that was given to me which was this.</p>
  
  <pre><code>def isPalindrome(phrase):
      forward = Queue()
      reverse = Stack()
      extractLetters(phrase, forward, reverse)
      return sameSequence(forward, reverse)
  
  #------------------------------------------------------------
  
  def extractLetters(phrase, q, s):
      for ch in phrase:
          if ch.isalpha():
              ch = ch.lower()
              q.enqueue(ch)
              s.push(ch)
  
  #------------------------------------------------------------
  
  def sameSequence(q, s):
      while q.size() &gt; 0:
          ch1 = q.dequeue()
          ch2 = s.pop()
          if ch1 != ch2:
              return False
      return True
  </code></pre>
  
  <p>Thanks to whoever helps me in advance!</p>