class Nod:
def __init__(self,data):
self.next=None
self.data=data
class Stiva:
def __init__(self,primu=None):
self.primu=primu
self.lungime=0
def Push(self,data): #adaugara la inceput
nod_nou=Nod(data)
self.lungime+=1
nod_nou.next=self.primu
self.primu=nod_nou
def Pop(self): #stergere de la inceput
curent=self.primu
data=curent
self.primu=curent.next
self.lungime-=1
print(data.data)
def size(self):
return self.lungime
def top(self):
return self.primu.data
def print(self):
curent=self.primu
while curent is not None:
print(curent.data)
curent=curent.next
l1=Stiva()
l1.Push(1)
l1.Push(2)
l1.Push(3)
l1.Push(4)
l1.print()
print("Lungimea este :{}\n".format(l1.size()))
l1.Pop()
print("Lungimea este :{}\n".format(l1.size()))
l1.print()
print("\n")
print(l1.top())
print("\n")
l1.print()
Implementarea unei Stive
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.