class Nod: def __init__(self,data):; class Coada: def __init__(self,primu=None): self.primu=primu self.lungime=0 def ENQUEUE(self,data): #adauga un element la finalul cozi nod_nou=Nod(data) = None if self.primu is None: nod_nou.anteriorul = None self.primu = nod_nou self.lungime+=1 return ultimul = self.primu while is not None: self.lungime+=1 ultimul = = nod_nou nod_nou.anteriorul = ultimul return def DEQUEUE(self): #sterge primul element din fata si returneaza elementul sters if self.primu is None: return None curent=self.primu self.lungime-=1 return def size(self): #returneza lunginmea cozi return self.lungime def front(self): #returneaza primul element din fata fara sa stearga return def print(self): curent=self.primu while curent is not None: print( c=Coada() c.ENQUEUE(1) c.ENQUEUE(2) c.ENQUEUE(3) c.ENQUEUE(4) c.print() print("primul element a cozi este {}".format(c.front())) print("\n") c.DEQUEUE() print("\n") c.print() print("\n") print("Lungime cozi este {}".format(c.size())) c.DEQUEUE() c.DEQUEUE() print("Lungime cozi este {}".format(c.size())) c.DEQUEUE() print("Lungime cozi este {}".format(c.size())) c.DEQUEUE() print("Lungime cozi este {}".format(c.size()))
Implementarea unei Cozi

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.