Python problem: "Write a Node class for singly linked structure. Define 3 node objects with which to put these data in them. "4", "-7", "34" " Here is the node code: """ File: node.py Node classes for one-way linked structures and two-way linked structures. """ class Node(object): def __init__(self, data, next = None): """Instantiates a Node with default next of None""" self.data = data self.next = next class TwoWayNode(Node): def __init__(self, data, previous = None, next = None): Node.__init__(self, data, next) self.previous = previous # Just an empty link node1 = None # A node containing data and an empty link node2 = Node("A", None) # A node containing data and a link to node2 node3 = Node("B", node2)
Python problem:
"Write a Node class for singly linked structure.
Define 3 node objects with which to put these data in them. "4", "-7", "34" "
Here is the node code:
"""
File: node.py
Node classes for one-way linked structures and two-way
linked structures.
"""
class Node(object):
def __init__(self, data, next = None):
"""Instantiates a Node with default next of None"""
self.data = data
self.next = next
class TwoWayNode(Node):
def __init__(self, data, previous = None, next = None):
Node.__init__(self, data, next)
self.previous = previous
# Just an empty link
node1 = None
# A node containing data and an empty link
node2 = Node("A", None)
# A node containing data and a link to node2
node3 = Node("B", node2)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images