Skip to content

Commit 5eeac54

Browse files
MoigeMatinoAgatha Bahati
andauthored
feat: add zipper lists v1 (#54)
Co-authored-by: Agatha Bahati <agatha@marketforce360.com>
1 parent d89ac46 commit 5eeac54

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

linked_lists/zipper_lists/__init__.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def zipper_lists(head_1, head_2):
2+
tracker = head_1
3+
current_1 = head_1.next
4+
current_2 = head_2
5+
count = 0
6+
7+
while current_1 is not None and current_2 is not None:
8+
if count % 2 == 0:
9+
tracker.next = current_2
10+
current_2 = current_2.next
11+
else:
12+
tracker.next = current_1
13+
current_1 = current_1.next
14+
15+
tracker = tracker.next
16+
count += 1
17+
18+
if current_1 is not None:
19+
tracker.next = current_1
20+
if current_2 is not None:
21+
tracker.next = current_2
22+
23+
return head_1

0 commit comments

Comments
 (0)