i am adding node before last node and getting issue, last 2 node printing infinte time. its working fine if i am adding before any other node def add_node_before_given_Node(self,data,x): ob1 = Create_Node(data) if self.head is None: print("LL is Empty") elif self.head.data is x: ob1.nref = self.head self.head.pref = ob1 self.head = ob1 else: n = self.head while n is not None: # we not take n.nref in while loop becz if we take the it will not go in last node if n.data is x: ob1.pref = n.pref ob1.nref = n n.pref.nref = ob1 n.pref = ob1 return #exit from function n= n.nref print("Given node is not present in LL")
Mam in add_before method can we use New_node.nref=n.pref.nref Instead of giving New_node=n But it gives attribute error,could you please tell me abt this..!
Can you please let me know which data structures is used to implement other data structures ? Like we use linked list to implement stack and que .... am right ? Then what about other data structures ? Which data structures do we need to implement other DS ?
class Node: def __init__(self, data): self.data = data self.prev = None self.next = None class DLinkedList: def __init__(self): self.head = None self.count = 0 def insert(self, data): node = Node(data) if self.head is None: self.head = node else: self.head.prev = node node.next = self.head self.head = node self.count +=1 def insert_at(self, data: any, index:int): if index==0: self.insert(data) elif index == self.count: self.append(data) elif index < self.count: n = self.head i = 0 while n.next is not None: if (index-1) == i: node = Node(data) n.next.prev = node node.next = n.next n.next = node self.count += 1 n = n.next i+=1 else: print("Can not insert at this position") def append(self, data): node = Node(data) if self.head is None: self.head = node else: n = self.head while n.next is not None: n = n.next n.next = node node.prev = n self.count += 1 def view_list(self)->str: string = "[" n = self.head while n is not None: string += f"{n.data}, " n = n.next return string[:-2] + "]" def at_index(self, index:int)->any: n = self.head i = 0 while n is not None: if index == i: return n.data n = n.next i+=1 def remove(self): n = self.head while n.next is not None: n = n.next n.prev.next = None self.count -= 1 def remove_at(self, index: int): n = self.head i = 0 if index == 0: self.head.next.prev = None self.head = self.head.next elif index == (self.count-1): self.remove() elif index >= self.count: print("Index out of reach") else: while n.next is not None: if index == i: n.prev.next = n.next n.next.prev = n.prev self.count -=1 n = n.next i+=1 dlist = DLinkedList() dlist.append(5) dlist.append(10) dlist.append(11) dlist.insert(2) dlist.insert_at(7,4) print(dlist.view_list()) dlist.remove_at(5) print(dlist.view_list()) print(dlist.count) print(dlist.at_index(3))
I was searching for python basics and i found u just like the way i wanted to be. Thanks nd keep going
Happy to hear that! :)
@@AmulsAcademy it's euphonious the way you explains it.thnx
Oooo God a lot to know a lot to learn from this wonderful channel.
Your videos are great as well as you voice and your explanation. So nice
Great teacher .I like the way explains and iam an fan of her teaching.... Thanks for the great eplain...❤❤❤❤❤❤
mam we can use add begin or end method instead of add before or after the first or last node insertion!? it's more easy and not confused
Nice Work ❤
good work
Thank you 😊
i am adding node before last node and getting issue, last 2 node printing infinte time. its working fine if i am adding before any other node
def add_node_before_given_Node(self,data,x):
ob1 = Create_Node(data)
if self.head is None:
print("LL is Empty")
elif self.head.data is x:
ob1.nref = self.head
self.head.pref = ob1
self.head = ob1
else:
n = self.head
while n is not None: # we not take n.nref in while loop becz if we take the it will not go in last node
if n.data is x:
ob1.pref = n.pref
ob1.nref = n
n.pref.nref = ob1
n.pref = ob1
return #exit from function
n= n.nref
print("Given node is not present in LL")
Gud morning ma'am and nice video explaination😁
Thank you :)
First comment but can't see video
Due to our mid examination's
All the best for 100k subscriber's soon 😘
😁👍🏻
Thank you but don't do that, watch videos if you like them then only hit like button :)
@@AmulsAcademy with Guts👍🏻
Tnq 😁
Mam
Mam in add_before method can we use
New_node.nref=n.pref.nref
Instead of giving
New_node=n
But it gives attribute error,could you please tell me abt this..!
Man please make videos on AI&ML
Mam pls put more videos for c programming
Sure :)
Can you please let me know which data structures is used to implement other data structures ?
Like we use linked list to implement stack and que .... am right ?
Then what about other data structures ? Which data structures do we need to implement other DS ?
Yes we can use linked list to implement stack queue tree etc :)
Add before method 2nd is not working it struck in infinitely loop and keep printing the entering node value.
Ma'am your videos are great......how can i contact you for doubts?
Thank you 😊
You can contact me here or Facebook page : amuls academy 😊
Ma'am your video is too good ❤️for python programmer
Ma'am please upload also tree graph related videos in python
Will upload soon :)
@@AmulsAcademy nice
👍
Thank you :)
❤️
😊
thank you ma'am!
Pleasure 😊
class Node:
def __init__(self, data):
self.data = data
self.prev = None
self.next = None
class DLinkedList:
def __init__(self):
self.head = None
self.count = 0
def insert(self, data):
node = Node(data)
if self.head is None:
self.head = node
else:
self.head.prev = node
node.next = self.head
self.head = node
self.count +=1
def insert_at(self, data: any, index:int):
if index==0:
self.insert(data)
elif index == self.count:
self.append(data)
elif index < self.count:
n = self.head
i = 0
while n.next is not None:
if (index-1) == i:
node = Node(data)
n.next.prev = node
node.next = n.next
n.next = node
self.count += 1
n = n.next
i+=1
else:
print("Can not insert at this position")
def append(self, data):
node = Node(data)
if self.head is None:
self.head = node
else:
n = self.head
while n.next is not None:
n = n.next
n.next = node
node.prev = n
self.count += 1
def view_list(self)->str:
string = "["
n = self.head
while n is not None:
string += f"{n.data}, "
n = n.next
return string[:-2] + "]"
def at_index(self, index:int)->any:
n = self.head
i = 0
while n is not None:
if index == i:
return n.data
n = n.next
i+=1
def remove(self):
n = self.head
while n.next is not None:
n = n.next
n.prev.next = None
self.count -= 1
def remove_at(self, index: int):
n = self.head
i = 0
if index == 0:
self.head.next.prev = None
self.head = self.head.next
elif index == (self.count-1):
self.remove()
elif index >= self.count:
print("Index out of reach")
else:
while n.next is not None:
if index == i:
n.prev.next = n.next
n.next.prev = n.prev
self.count -=1
n = n.next
i+=1
dlist = DLinkedList()
dlist.append(5)
dlist.append(10)
dlist.append(11)
dlist.insert(2)
dlist.insert_at(7,4)
print(dlist.view_list())
dlist.remove_at(5)
print(dlist.view_list())
print(dlist.count)
print(dlist.at_index(3))
Are u telugu speaking or hindi?☺️
Kannada 😊
@@AmulsAcademy unexpected 😀 anyways nice... you're ds course is so underrated
Can you teach python in tamil..?
No, i don't know Tamil :)
@@AmulsAcademy tamil very very simple just try to learn free time
Mam are you from Telugu or kannada