Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created May 24, 2017 19:19
Show Gist options
  • Select an option

  • Save mortymacs/f95ae18327e91b87bae95a5daa92d961 to your computer and use it in GitHub Desktop.

Select an option

Save mortymacs/f95ae18327e91b87bae95a5daa92d961 to your computer and use it in GitHub Desktop.
Sample LinkedList in Python
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