Skip to content

Commit d80e35e

Browse files
authored
Pop returns value (#125)
1 parent 0428473 commit d80e35e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ __pycache__/
5858
################
5959
.vscode/
6060
.vs/
61+
62+
# Other Files #
63+
################
64+
.idea/
65+
build/
66+
dist/

pydatastructs/linear_data_structures/linked_lists.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def pop_left(self):
210210
The leftmost element of linked
211211
list.
212212
"""
213-
self.extract(0)
213+
return self.extract(0)
214214

215215
def pop_right(self):
216216
"""
@@ -224,7 +224,7 @@ def pop_right(self):
224224
The leftmost element of linked
225225
list.
226226
"""
227-
self.extract(-1)
227+
return self.extract(-1)
228228

229229
def extract(self, index):
230230
"""
@@ -435,7 +435,7 @@ def pop_left(self):
435435
The leftmost element of linked
436436
list.
437437
"""
438-
self.extract(0)
438+
return self.extract(0)
439439

440440
def pop_right(self):
441441
"""
@@ -449,7 +449,7 @@ def pop_right(self):
449449
The leftmost element of linked
450450
list.
451451
"""
452-
self.extract(-1)
452+
return self.extract(-1)
453453

454454
def extract(self, index):
455455
"""

pydatastructs/linear_data_structures/tests/test_linked_lists.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def test_DoublyLinkedList():
1717
dll.insert_at(0, 2)
1818
dll.insert_at(-1, 9)
1919
dll.extract(2)
20-
dll.extract(0)
21-
dll.extract(-1)
20+
assert dll.pop_left().data == 2
21+
assert dll.pop_right().data == 4
2222
dll[-2].data = 0
2323
assert str(dll) == "[7, 5, 1, 6, 1, 0, 9]"
2424
assert len(dll) == 7
@@ -50,8 +50,8 @@ def test_SinglyLinkedList():
5050
sll.insert_at(0, 2)
5151
sll.insert_at(-1, 9)
5252
sll.extract(2)
53-
sll.extract(0)
54-
sll.extract(-1)
53+
assert sll.pop_left().data == 2
54+
assert sll.pop_right().data == 6
5555
sll[-2].data = 0
5656
assert str(sll) == "[2, 4, 1, 0, 9]"
5757
assert len(sll) == 5
@@ -83,8 +83,8 @@ def test_SinglyCircularLinkedList():
8383
scll.insert_at(0, 2)
8484
scll.insert_at(-1, 9)
8585
scll.extract(2)
86-
scll.extract(0)
87-
scll.extract(-1)
86+
assert scll.pop_left().data == 2
87+
assert scll.pop_right().data == 6
8888
scll[-2].data = 0
8989
assert str(scll) == "[2, 4, 1, 0, 9]"
9090
assert len(scll) == 5
@@ -118,8 +118,8 @@ def test_DoublyCircularLinkedList():
118118
dcll.insert_at(0, 2)
119119
dcll.insert_at(-1, 9)
120120
dcll.extract(2)
121-
dcll.extract(0)
122-
dcll.extract(-1)
121+
assert dcll.pop_left().data == 2
122+
assert dcll.pop_right().data == 4
123123
dcll[-2].data = 0
124124
assert str(dcll) == "[7, 5, 1, 6, 1, 0, 9]"
125125
assert len(dcll) == 7

0 commit comments

Comments
 (0)