+ 1

Please can someone carefully walk me through the code in Linked lists in Python?

class Node: def __init__(self, data, next): self.data = data self.next = next class LinkedList: def __init__(self): self.head = None def add_at_front(self, data): self.head = Node(data, self.head) def add_at_end(self, data): if not self.head: self.head = Node(data, None) return curr = self.head while curr.next: curr = curr.next curr.next = Node(data, None) def get_last_node(self): n = self.head while(n.next != None): n = n.next return n.data def is_empty(self): return self.head == None def print_list(self): n = self.head while n != None: print(n.data, end = " => ") n = n.next print() s = LinkedList() s.add_at_front(5) s.add_at_end(8) s.add_at_front(9) s.print_list() print(s.get_last_node()) This one⬆️⬆️⬆️⬆️

31st Aug 2021, 11:16 AM
Obinna
Obinna - avatar
5 Réponses
+ 1
Especially that "curr.next" part
31st Aug 2021, 11:18 AM
Obinna
Obinna - avatar
+ 1
Oh i see...so i should just forget about learning that and focus on strengthening my use of normal lists in Python
31st Aug 2021, 9:29 PM
Obinna
Obinna - avatar
0
So you're saying that i should learn C to get a better insight to the code??
31st Aug 2021, 4:39 PM
Obinna
Obinna - avatar