In: Computer Science
# List the two private member variables (including name and functionality) in the node class.
#Write a general pattern for a loop statement that traverses all the nodes of a linked list
Node Class:
class Node:
def __init__(self, init_data, init_next=None):
# Initializing two
private data members
self.__data = init_data
self.__next =
init_next
# Getter and Setter Methods
def get_data(self):
return self.__data
def get_next(self):
return self.__next
def set_data(self, new_data):
self.__data = new_data
def set_next(self, new_next):
self.__next = new_next
def __str__(self):
return str(self.__data)
# Adding a node to list
def add_after(self, value):
new_node = Node(value,self.__next
)
self.__next = new_node
# Removes a node from list
def remove_after(self):
self.__next =
self.__next.get_next()
___________________________________________________________________________________________
# General pattern for a loop statement that
traverses all the nodes of a linked list
for node in self.nodes:
# Printing current node data
print(node.get_data())