Created
May 24, 2017 19:19
-
-
Save mortymacs/f95ae18327e91b87bae95a5daa92d961 to your computer and use it in GitHub Desktop.
Sample LinkedList in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node: | |
| _data = None | |
| _next = None | |
| def __init__(self, data = None, next_node = None): | |
| self._data = data | |
| self._next = next_node | |
| # DATA PROPERTY | |
| @property | |
| def data(self): | |
| return self._data | |
| @data.setter | |
| def data(self, data): | |
| self._data = data | |
| # NEXT NODE PROPERTY | |
| @property | |
| def next(self): | |
| return self._next | |
| @next.setter | |
| def next(self, next): | |
| self._next = next | |
| # SAMPLE USAGE | |
| a = Node() | |
| b = Node() | |
| c = Node() | |
| a.data = 10 | |
| a.next = b | |
| b.data = 20 | |
| b.next = c | |
| c.data = 30 | |
| print("A->B->C: {}".format(a.next.next.data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment