Untitled
unknown
plain_text
a year ago
937 B
6
Indexable
class Node:
def __init__(self, info=None):
self.info = info
self.next = None
class Stack:
def __init__(self):
self.first = Node()
def isEmpty(self):
return self.first.next is None
def push(self, info):
new_node = Node(info)
new_node.next = self.first.next
self.first.next = new_node
def pop(self):
popped_node = self.first.next
self.first.next = popped_node.next
return popped_node.info
def top(self):
return self.first.next.info
def Check(string):
string = Stack()
for chr in string:
if chr in {'[','(','{'}:
string.push(chr)
else:
if chr in {']',')','}'}:
if string.isEmpty():
return False
def main():
mystack = Stack()
mystack.push(5)
print(mystack.top())
print(mystack.pop())
print(mystack.isEmpty())
main()Editor is loading...
Leave a Comment