0% found this document useful (0 votes)
14 views1 page

LL Append

Uploaded by

Duke Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

LL Append

Uploaded by

Duke Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class Node:

def __init__(self, value):


self.value = value
self.next = None

class LinkedList:
def __init__(self, value):
new_node = Node(value)
self.head = new_node
self.tail = new_node
self.length = 1

def print_list(self):
temp = self.head
while temp is not None:
print(temp.value)
temp = temp.next

def append(self, value):


new_node = Node(value)
if self.length == 0:
self.head = new_node
self.tail = new_node
else:
self.tail.next = new_node
self.tail = new_node
self.length += 1

my_linked_list = LinkedList(1)

my_linked_list.append(2)

my_linked_list.print_list()

You might also like