LinkedLists Flashcards
1
Q
Given the Node Class, write the code for:
creating an empty list
A
x = Linkedlist(value)
2
Q
Given the Node Class, write the code for:
Adding new node to head of linkedlist
A
def add_head(self, value): new_node = Node(value) new_node.set_next(self.head) self.head = new_node
3
Q
Given the Node Class, write the code for:
Adding new node to tail of linkedlist
A
def add_tail(self, value): new_node = Node(value) current = self.head while current.get_next() != None: current = current.get_next() current.set_next(new_node)
4
Q
Given the Node Class, write the code for:
Removing node from tail of linkedlist
A
def remove_tail(self, value): previous = None current = self.head while current.get_next() != None: previous = current current = current.get_next() previous.set_next(current.get_next())
5
Q
Given the Node Class, write the code for:
Removing node from head of linkedlist
A
def remove_head(self): previous = None current = self.head self.head = current.get_next()