DSA Programs
DSA Programs
Aim: Write a program to find the sum and product of two matrices using the list data structure.
Code:
# Sum of matrices
range(rows)]
# Product of matrices
# Example Matrices
# Operations
Code:
class Node:
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
new_node = Node(data)
new_node.next = self.head
self.head = new_node
temp = self.head
self.head = temp.next
temp = None
return
prev = None
temp = temp.next
if temp is None:
return
prev.next = temp.next
temp = None
def display(self):
temp = self.head
while temp:
temp = temp.next
print("None")
# Example Usage
ll = LinkedList()
ll.add(1)
ll.add(2)
ll.add(3)
ll.display()
ll.delete(2)
ll.display()
Output: