class Node(object):
def __init__(self, val, nxt = None):
self.val = val
self.nxt = nxt
class Stack(object):
size = 0
def __init__(self, top = None):
self.top = top
def push(self, data):
if self.top is None:
self.top = Node(data)
else:
newNode = Node(data)
newNode.next = self.top
self.top = newNode
size += 1
def pop(self):
if self.top is None:
return None
else:
popped = self.top.val
self.top = self.top.next
size -= 1
return popped
Implementare in Python despre problema 1 de la seminar a stivei
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.