Inserting/Adding Elements Before The Given Node in The Linked List | Python Program

preview_player
Показать описание
In this Python Programming video tutorial you will learn about how to implement Linked List data structure in python 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.

To implement Singly Linked List we are using class concepts here.

Program:
def add_before(self,data,x):
print("Linked List is empty!")
return
new_node = Node(data)
return
break
print("Node is not found!")
else:
new_node = Node(data)

#DataStructures #PythonPrograms #LinkedList

For more free tutorials on computer programming
Рекомендации по теме
Комментарии
Автор

For add_middle_before :--


def add_middle_after(self, data, x):
val=self.head
val_1=self.head
while val is not None:
if val.data==x:
result=val
break
val=val.ref
while val_1 is not None:
if val_1.ref==result:
break
val_1=val_1.ref
if val is None:
print("empyt linked_list")
else:
new_node=Node(data)
val_1.ref=new_node
new_node.ref=result

It's working

weslynalluri
visit shbcf.ru