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

Apt74 Justpasteit

Uploaded by

thetruths2024
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)
21 views3 pages

Apt74 Justpasteit

Uploaded by

thetruths2024
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

Downloaded from: justpaste.

it/apt74

DLL-Ops
class Node:
def __init__(self,d):
self.prev=None
self.data=d
self.next=None

class DLL:
def __init__(self):
self.head=None
self.tail=None

def insert_at_start(self,v):
new_node=Node(v)

if not self.head:
self.head=new_node
return

if not self.head.next:
new_node.next=self.head
self.head.prev=new_node
self.head= new_node
self.tail=self.head.next
return

new_node.next=self.head
self.head.prev=new_node
self.head=new_node

def insert_at_end(self,v):
new_node=Node(v)
self.tail.next=new_node
new_node.prev=self.tail
self.tail=new_node
return

def remove(self,v):
if self.head.data==v:
self.head=self.head.next
self.head.prev=None
return
if self.tail.data==v:
self.tail=self.tail.prev
self.tail.next=None
return

current=self.head
while current and current.data!=v:
current=current.next

if not current:
print("Value Not Found")
return

current.prev.next=current.next
if current.next:
current.next.prev=current.prev

def fTrace(self):
if not self.head.next:
print(self.head.data)
return
current=self.head
while current:
print(current.data,end="<-->")
current=current.next
def bTrace(self):
current=self.tail
while current:
print(current.data,end="<-->")
current=current.prev

You might also like