This commit is contained in:
2024-04-03 11:26:06 +02:00
parent c445868af4
commit e9fccea523
2 changed files with 19 additions and 8 deletions

View File

@@ -73,8 +73,15 @@ class ListeChainee:
self.tete = None
def __add__(self, other):
current = self.tete
while current.next:
current = current.next
current.next = other.tete
return self
current1 = self.tete
current2 = other.tete
LC = ListeChainee()
while current1 or current2:
val1 = current1.value if current1 else 0
val2 = current2.value if current2 else 0
LC.add_last(val1 + val2)
if current1:
current1 = current1.next
if current2:
current2 = current2.next
return LC

View File

@@ -21,9 +21,6 @@ def test_listechainee():
LC.empty()
print(LC.isEmpy())
LC.printLinkedList()
LC.add_first(1)
LC.add_first(2)
LC.add_first(2)
LC.add_first(35)
LC.add_last(44)
LC.printLinkedList()
@@ -34,6 +31,13 @@ def test_listechainee():
LC2.printLinkedList()
LC3 = LC + LC2
LC3.printLinkedList()
LC4 = ListeChainee()
LC4.add_first(1)
LC4.add_first(1)
LC4.add_first(1)
LC4.add_first(1)
LC5 = LC3 + LC4
LC5.printLinkedList()
if __name__ == "__main__":