Linked Lists

 Linked Lists


A linked list is a collection of nodes where each node contains data and a reference to the next node in the list.


python


# Define the node class

class Node:

    def __init__(self, data):

        self.data = data

        self.next = None

        

# Create a linked list

head = Node(1)

head.next = Node(2)

head.next.next = Node(3)


# Traverse the linked list

curr_node = head

while curr_node:

    print(curr_node.data)

    curr_node = curr_node.next

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...