Skip to content

Commit

Permalink
Merge pull request #74 from eeshannarula29/rep-data
Browse files Browse the repository at this point in the history
Rep data
  • Loading branch information
eeshannarula29 authored Apr 21, 2021
2 parents 487043f + d780a57 commit aecaad3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions BinaryTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def __str__(self) -> str:
"""
return self.display_branched()

def __repr__(self) -> str:
return 'BinarySearchTree( \n' + self.display_branched() + ')'

def display(self, indented: Optional[bool] = False):
"""Print a string representation of this BST"""
if indented:
Expand Down
3 changes: 3 additions & 0 deletions DoublyLinkedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def __str__(self) -> str:
"""
return '[' + ' <--> '.join([str(element) for element in self]) + ']'

def __repr__(self) -> str:
return f'DoubleLinkedList({self.__str__()})'

def count(self, item: Any) -> int:
"""Return the number of times the given item occurs in this list.
"""
Expand Down
15 changes: 13 additions & 2 deletions Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def __init__(self, _vertex: _Vertex) -> None:
def __repr__(self) -> str:
"""Return string representation of vertex"""

string_so_far = '{ \n'
string_so_far = 'NeighboursView({ \n'

for neighbour in self._vertex.neighbours:
string_so_far += \
' {' + f'{neighbour}: {self._vertex.neighbours[neighbour]["attributes"]}' + '}, \n'

return string_so_far + '}'
return string_so_far + '})'

def __setitem__(self, other: Any, properties: dict) -> None:
"""Set a property of the edge between self and other
Expand Down Expand Up @@ -564,3 +564,14 @@ def __str__(self) -> str:
string_representation += '}'

return string_representation

def __repr__(self) -> str:
"""Return a string representation of the graph"""
string_representation = '{ \n'

for item in self.vertices:
string_representation += f'{item}: {self[item].get_neighbours()} \n'

string_representation += '}'

return 'Graph(' + string_representation + ')'
3 changes: 3 additions & 0 deletions LinkedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def __str__(self) -> str:
"""
return '[' + ' -> '.join([str(element) for element in self]) + ']'

def __repr__(self) -> str:
return f'LinkedList({self.__str__()})'

def insert(self, i: int, item: Any) -> None:
"""Insert the given item at index i in this list.
"""
Expand Down
22 changes: 3 additions & 19 deletions Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,10 @@ def display(self, key: Optional[Callable] = lambda x: x) -> None:
print(string_so_far)

def __str__(self) -> str:
return '[' + ' -> '.join([str(element) for element in self._items]) + ']'

string_so_far = ''

temp = ''

items = self._items.to_list()

for index, item in enumerate(items):
if index < len(items) - 1:
temp += f' {item} ->'
else:
temp += f' {item}'

string_so_far += 'Entry ' + '-' * len(temp) + '> Exit \n'

string_so_far += ' ' + temp + '\n'

string_so_far += '------' + '-' * len(temp) + '------'

return string_so_far
def __repr__(self) -> str:
return f'Queue({self.__str__()})'


class EmptyQueueError(Exception):
Expand Down
3 changes: 3 additions & 0 deletions Stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def __str__(self) -> str:

return string_so_far

def __repr__(self) -> str:
return f'Stack({self.items})'


class EmptyStackError(Exception):
def __str__(self) -> str:
Expand Down

0 comments on commit aecaad3

Please sign in to comment.