You are on page 1of 3

MINI PROJECT

NAME : JEEVA THAARINI D


REG NO : 210622205027
YEAR : IIND
DEPARTMENT : IT
SUBJECT : DATA STRUCTURES
AND ALGORITHMS
SUB CODE : CD3291
TOPIC : LINKED LIST
IMPLEMENTATION
LINKED LIST IMPLEMENTATION
Project Description:
Implement a linked list data structure from scratch. Linked lists are fundamental in computer science
and provide insights into memory management and data manipulation. By creating your linked list,
gain a deep understanding of how linked data structures work.A linked list implementation project
involves creating a linked list data structure and implementing various operations such as insertion,
deletion, searching, and traversal.

Code:
class Node:
def __init__(self, data):
self.data = data
self.next = None

class LinkedList:
def __init__(self):
self.head = None

def is_empty(self):
return self.head is None

def append(self, data):


new_node = Node(data)
if self.is_empty():
self.head = new_node
else:
last_node = self.head
while last_node.next:
last_node = last_node.next
last_node.next = new_node

def prepend(self, data):


new_node = Node(data)
new_node.next = self.head
self.head = new_node

def delete(self, key):


current_node = self.head

if current_node and current_node.data == key:


self.head = current_node.next
current_node = None
return

prev_node = None
while current_node and current_node.data != key:
prev_node = current_node
current_node = current_node.next

if current_node is None:
return

prev_node.next = current_node.next
current_node = None
def search(self, key):
current_node = self.head
while current_node:
if current_node.data == key:
return True
current_node = current_node.next
return False

def display(self):
current_node = self.head
while current_node:
print(current_node.data, end=" -> ")
current_node = current_node.next
print("None")

# Example usage:
linked_list = LinkedList()

linked_list.append(1)
linked_list.append(2)
linked_list.append(3)
linked_list.prepend(0)

print("Original Linked List:")


linked_list.display()

linked_list.delete(2)

print("\nLinked List after deleting node with value 2:")


linked_list.display()

print("\nIs 3 in the linked list?", linked_list.search(3))

Output:
Original Linked List:
0 -> 1 -> 2 -> 3 -> None

Linked List after deleting node with value 2:


0 -> 1 -> 3 -> None

Is 3 in the linked list? True

Conclusion:
This implementation includes basic operations such as appending, prepending, deleting, searching, and
displaying the linked list.

You might also like