mirror of
https://github.com/jlengrand/Coding4Interviews.git
synced 2026-03-10 08:11:24 +00:00
35 lines
679 B
Python
35 lines
679 B
Python
"""
|
|
Implementation of Linked Lists
|
|
|
|
@jlengrand
|
|
2013/12
|
|
"""
|
|
|
|
class SingleListItem():
|
|
"""
|
|
Item from a Single Linked List.
|
|
Contains only a previous next element, and a value
|
|
"""
|
|
def __init__(self, value, nexti=None):
|
|
self.value = value
|
|
self.nexti = nexti
|
|
|
|
def has_next(self):
|
|
"""
|
|
Returns True if the item has a next value
|
|
"""
|
|
return not (self.nexti is None)
|
|
|
|
class SingleLinkedList():
|
|
"""
|
|
Linked list with only one link between items.
|
|
The list can only be traversed one way"""
|
|
|
|
def __init__():
|
|
self.root= SinglelistItem(None, None) # The head
|
|
|
|
if __name__ == "__main__":
|
|
a = 12
|
|
t = SingleListItem(12)
|
|
print t.has_next()
|