LinkedLists Flashcards

1
Q

Given the Node Class, write the code for:

creating an empty list

A

x = Linkedlist(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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())
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly