

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Bài tập:
def popS(self): if self.size <= 0 : return ("No element in the Stack") else: self.top-= self.size-= return self.stack.pop() def isEmpty(self): def getTop(self): AStack = Stack() AStack.pushS("Mon") AStack.pushS("Tue") AStack.pushS("Wed") AStack.pushS("Thu") print(AStack.popS()) print(AStack.popS())
When the above code is executed, it produces the following result − Thu Wed
class Queue: def init(self): self.queue = list() def addtoQ(self,dataval):
if dataval not in self.queue: self.queue.insert( 0 ,dataval) return True return False
def removefromQ(self): if len(self.queue)> 0 : return self.queue.pop() return ("No elements in Queue!") TheQueue = Queue() TheQueue.addtoq("Mon") TheQueue.addtoq("Tue") TheQueue.addtoq("Wed") print(TheQueue.removefromq()) print(TheQueue.removefromq())
When the above code is executed, it produces the following result − Mon Tue