1. 232 : implement Queue using Stacks

class MyQueue(object):

    def __init__(self):
        self.data = []
        self.size = 0
        
        """
        Initialize your data structure here.
        """
        

    def push(self, x):
        self.data.append(x)
        self.size += 1
        #print self.data
        
        """
        Push element x to the back of queue.
        :type x: int
        :rtype: None
        """
        
    def pop(self):
        if(self.size > 0):
            self.size -= 1
            pop_data = self.data[0]
            self.data.remove(pop_data)
            return pop_data
            
        return 0
        
        """
        Removes the element from in front of queue and returns that element.
        :rtype: int
        """
        

    def peek(self):
        if(self.size > 0):
            #print self.data[0]
            return self.data[0]
        else:
            return 0
        
        """
        Get the front element.
        :rtype: int
        """
        

    def empty(self):
        if self.size == 0:
            return 1
        else:
            return 0
        
        """
        Returns whether the queue is empty.
        :rtype: bool
        """
        


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()

 

Posted by 공놀이나하여보세
,