Doubly Linked List | Program | Deletion Operation | Data Structures

Опубликовано: 13 Март 2025
на канале: Amulya's Academy
25,021
532

In this Python Programming video tutorial you will learn about doubly Linked List data structure and also you will write the program for deletion operation in detail.

Data structure is a way of storing and organising the data so that it can be accessed effectively.
Linked List is a linear data structure made up of chain of nodes in which each node contains a data field and link or reference.

There are different types of linked list. Here we will discuss about 3 common types of linked list. doubly linked list is one of them. Here we will discuss doubly linked list operations and definitions in detail.

Here we will write 3 methods for deletion operation.

def delete_begin(self):
if self.head is None:
print("DLL is empty can't delte !")
return
if self.head.nref is None:
self.head = None
print("DLL is empty after deleting the node!")
else:
self.head = self.head.nref
self.head.pref = None

def delete_end(self):
if self.head is None:
print("DLL is empty can't delte !")
return
if self.head.nref is None:
self.head = None
print("DLL is empty after deleting the node!")
else:
n = self.head
while n.nref is not None:
n = n.nref
n.pref.nref = None

def delete_by_value(self,x):
if self.head is None:
print("DLL is empty can't delte !")
return
if self.head.nref is None:
if x==self.head.data:
self.head = None
else:
print("x is not present in DLL")
return
if self.head.data == x:
self.head = self.head.nref
self.head.pref = None
return
n = self.head
while n.nref is not None:
if x==n.data:
break
n = n.nref
if n.nref is not None:
n.nref.pref = n.pref
n.pref.nref = n.nref
else:
if n.data==x:
n.pref.nref = None
else:
print("x is not present in dll!")



#DataStructures #PythonPrograms #LinkedList

For more free tutorials on computer programming
  / amulsacademy  
twitter.com/AmulsAcademy