0% found this document useful (0 votes)
2 views3 pages

Del As Sai

THIS IS DSA ASSIGNMENT

Uploaded by

Rahul Abhiram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Del As Sai

THIS IS DSA ASSIGNMENT

Uploaded by

Rahul Abhiram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DSA ASSIGNMENT 4

NAME:Sai Kumar Adireddi

ROLL NO:22ME8145

REG NO:22U10705

class Node:

def __init__(self, value):

self.data = value

self.next = None

class LinkedList:

def __init__(self):

self.head = None

def insert_end(self, value):

if self.head == None:

self.head = Node(value)

return

new_node = self.head

while new_node.next != None:

new_node = new_node.next

new_node.next = Node(value)

def display(self):

if self.head == None:

print("LinkedList is Empty")

return

node = self.head

while node != None:


print(node.data, end=" ")

node = node.next

print("\n")

def insert_begin(self, value):

node = self.head

if self.head == None:

self.head = Node(value)

return

self.head = Node(value)

self.head.next = node

def delete(self, find):

if self.head == None:

return print("Head is Empty")

elif self.head.data == find:

if self.head.next == None:

self.head = None

return print(f"{find} is Deleted, LinkedList is Empty")

else:

self.head = self.head.next

return print(f"{find} is Deleted")

else:

node = self.head

while node.next != None:

if node.next.data == find:

node.next = node.next.next

return print(f"{find} is Deleted")

node = node.next
return print(f"{find} is Not Found")

ll = LinkedList()

ll.insert_begin(5)

ll.insert_end(76)

ll.insert_begin(51)

ll.insert_begin(88)

ll.display()

ll.delete(51)

ll.delete(88)

ll.delete(76)

ll.display()

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy