Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added str methods for ODA and DODA #208

Merged
merged 7 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pydatastructs/linear_data_structures/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def fill(self, elem):
def __len__(self):
return self._size

def __str__(self):
return str(self._data)


class DynamicArray(Array):
"""
Expand Down Expand Up @@ -255,6 +258,9 @@ def delete(self, idx):
def size(self):
return self._size

def __str__(self):
return str(self._data[:self._last_pos_filled+1])
HarsheetKakar marked this conversation as resolved.
Show resolved Hide resolved

class ArrayForTrees(DynamicOneDimensionalArray):
"""
Utility dynamic array for storing nodes of a tree.
Expand Down
2 changes: 2 additions & 0 deletions pydatastructs/linear_data_structures/tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_OneDimensionalArray():
ODA = OneDimensionalArray
A = ODA(int, 5, [1.0, 2, 3, 4, 5], init=6)
A[1] = 2.0
assert str(A) == '[1, 2, 3, 4, 5]'
assert A
assert ODA(int, [1.0, 2, 3, 4, 5], 5)
assert ODA(int, 5)
Expand All @@ -27,6 +28,7 @@ def test_DynamicOneDimensionalArray():
A.append(2)
A.append(3)
A.append(4)
assert str(A) == '[1, 2, 3, 4]'
HarsheetKakar marked this conversation as resolved.
Show resolved Hide resolved
A.delete(0)
A.delete(0)
A.delete(15)
Expand Down