Mam, I have a question! For finding the node which node.data =x . That node may be not unique right? Because there may be two node like node1 and node2 such that node1.data= x as well as node2.data=x. Then how can we find that particular node, which I required to found?.
my answer for your question: it all depends on your scenario. if your requirement is to stop at the earliest node match(node1.data =x), then you can 'break' it after adding your new node. else, you can continue your search and repeat it after your second match(node2.data=x) and so on... PFB code: def add_after(self, data, x): n = self.head while n: if n.data == x: new_node = Node(data) new_node.ref = n.ref n.ref = new_node # break n = n.ref if n is None: print('{} is not available'.format(x))
Mam ,I have just thought of different way of coding to this same topic ..like if we assume x as position where we want to insert node ,assuming that first node starts from zeroth position .if we follow this method we would not be able to write different codes for After node and before node... Below is the code.. def insert_after_nodes(self,data,x): newnode=node(data) temp=self.head i=1 while(i
Hi Mahendra, 13.12 - 13.22 "listen here" - that means, if x is not there in our linked list, the value of n will be None because of the (n = n.ref) statement in while loop, i.e. because of the while loop, after traversing the entire linked list, value of n will be none, as the last node always points to None. That is why the "if statement" is like that. And, if we are getting the x in our linked list, the value of n cannot be None. I hope this clears your doubt :)
While we are searching for node x and traversing, what to do if there duplicate data in nodes and we are talking about 2nd duplicate value which our goal x..? Can any one please explain
Who will tell u that previous node value by which u would traverse till that nd insert after that. Bcoz u will be given a linked list nd just position will be given to u not previous node data value. Bcoz to access previous node data value u have to traverse uptill that otherwise how can u get that? Here u know it’s 100 beforehand That's why u r using that but in real scenerio if any other will make the list nd tell u to insert a element in a certain position then how can u do that?? I think we can take a counter here nd increment that till before the mentioned position like if position 3 increment that counter till 2, like Count = 0 n = New_node While count
Good tutorial 👍 Question :- What happen if link list contain dublicate number ? Eg :- 5,5,5,15 Now I want to add 1000 number after 2nd 5 of index 1. 5,5,___HERE___,5,15 Please help
Object, Python is all about object even if you are defining a function then at the time of calling you are making an object. So, in other word object is like an address/reference of that particular node or function or class. Example def fun(): print("hello") a = fun() a() So, in above example when fun() is called then it actually creats an object and that object is now assigned to 'a' and with the help of that object you again called the same function fun() Anyone is welcome to improve my explanation
insert value by index class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None self.len = 0 def view(self)-> str: string = "[" if self.head is None: return "[]" else: while self.head is not None: string += f"{self.head.data}, " self.head = self.head.next return string[:-2] + "]" def insert(self, data: any): if self.head is None: self.head = Node(data) self.len += 1 else: new_node = Node(data) new_node.next = self.head self.head = new_node self.len += 1 def append(self,data: any): if self.head is None: self.head = Node(data) self.len += 1 else: n = self.head while n.next is not None: n = n.next n.next = Node(data) self.len += 1 def insert_at(self, data: any, index: int)-> None: n = self.head count = 0 if index > self.len: print(f"Error: Can not add data into position {index}") elif index == self.len: self.append(data) elif index == 0: self.insert(data) else: while n is not None: if count == (index-1): new_node = Node(data) new_node.next = n.next n.next = new_node self.len += 1 n = n.next count += 1
The code that you are showing here is not working as it is, suppose your LinkedList is 10 -> 20 -> 30 ->40, and you have to add node after 20, then the print_ll() will not print the first node(10). Code is note working properly, My code is. class Node(): def __init__(self,data):
self.data=data self.ref=None class linkedlist(): def __init__(self): self.head=None def print_ll(self):
if self.head is None: print("Linkedlist is empty") else: while self.head is not None: print(self.head.data, "--->",end=' ') self.head=self.head.ref def add_begin(self,data): new_node=Node(data) if self.head is None: self.head=new_node else: new_node.ref=self.head.ref self.head=new_node def add_at_end(self,data): new_node=Node(data) if self.head is None: self.head=new_node else: while self.head.ref is not None: self.head=self.head.ref self.head.ref=new_node def add_in_between(self,data,afternode): while self.head is not None: if afternode==self.head.data: break
self.head=self.head.ref if self.head is None: print("Item is Not present in list") else: new_node=Node(data) new_node.ref=self.head.ref self.head.ref=new_node l=linkedlist() l.add_begin(25) l.add_at_end(30) l.add_begin(20) l.add_at_end(90) l.add_begin(1) l.add_at_end(1800) l.add_in_between(1000,20) l.print_ll()
Using a website like pythontutor and adding the code (which you can find in the description of the previous linked list videos up to now) might make it clear. It goes through every step of the code and shows exactly what it does with diagrams. That's what I'm using. Best of luck in your studies and work.
Ohh god this channel is soo underrated... :(
Thank you :)
@@AmulsAcademy please upload full playlist of DsA with python or else bring a full structured course, I'm ready to purchase
I agree 👍
I personally never comment, but after watching your videos, I really want to say that you are just awesome at explaination.
Thank you 😊❤️
@@AmulsAcademy how do i contact u , i still have doubts
I have Watched your complete series on LL, was searching for an LL explanation in python. Great explanation,articulate it was. Thank you
Amulya, ...Really nice, and well balanced both practically and theoritically.
thank you.
You're most welcome :)
One of the best channel to learn dsa in python ... understood linked list by watching your videos at first time itself ... nice explanation
Your channel is the reason why I have not dropped Computer Science yet. Thanks a lot...!!!
Best channel ever found..... Tq so much with lots of love ❤
best channel i have ever found on DSA course.worth watching ur videos
What a great clarity in teaching data structures!! 😃😃😃
Mam I will never forget your "chuck" . 😚
I really love you video, it's very clear and detailed. ps: this is my first time to comment
Thank you so much! :)
For this difficult topic you made it so easy to understand! what an excellent explaination!
We can all agree that she's one great teacher
Amazing voice with wonderful explanation
Thanks a lot 😊
Amezing Learning
You have explained very well mam
Thanks for providing a very nive titerial
You Are A mind-blowing person
Mam, I have a question! For finding the node which node.data =x . That node may be not unique right? Because there may be two node like node1 and node2 such that node1.data= x as well as node2.data=x. Then how can we find that particular node, which I required to found?.
my answer for your question: it all depends on your scenario. if your requirement is to stop at the earliest node match(node1.data =x), then you can 'break' it after adding your new node. else, you can continue your search and repeat it after your second match(node2.data=x) and so on...
PFB code:
def add_after(self, data, x):
n = self.head
while n:
if n.data == x:
new_node = Node(data)
new_node.ref = n.ref
n.ref = new_node
# break
n = n.ref
if n is None:
print('{} is not available'.format(x))
Nice video mam plz complete this series as soon as possible plz
I will try my best.
Ohh God..
U r Fantastic..
Thank You soo much 🥺
You Are Amazing !!! your Explanation is Amazing
you helped me a lot Thank you !!!!
best tuts so far
Nice Explanation
Mam ,I have just thought of different way of coding to this same topic ..like if we assume x as position where we want to insert node ,assuming that first node starts from zeroth position .if we follow this method we would not be able to write different codes for After node and before node... Below is the code..
def insert_after_nodes(self,data,x):
newnode=node(data)
temp=self.head
i=1
while(i
This position based approach is much better and efficient .
Love your explanation
Thank you :)
Please where is the videos you have explained class for node and linked list and travasel?
14:10second if statement I got that, but a little confusion , thanks for the vedio🙌🙌
Hi Mahendra,
13.12 - 13.22 "listen here" - that means, if x is not there in our linked list, the value of n will be None because of the (n = n.ref) statement in while loop, i.e. because of the while loop, after traversing the entire linked list, value of n will be none, as the last node always points to None. That is why the "if statement" is like that. And, if we are getting the x in our linked list, the value of n cannot be None.
I hope this clears your doubt :)
Shit. I have wasted my money on useless DS course on Udemy. I wish I found your course somewhat earlier... Thanks Amulya
Thanks madam
I learnt a lot
👍🤝
It's my pleasure :)
When will you continue making video's?😥
Thank u so much akka for ur teaching ☺️☺️☺️
While we are searching for node x and traversing, what to do if there duplicate data in nodes and we are talking about 2nd duplicate value which our goal x..? Can any one please explain
Mam you are Vera level
What do you studyed
BE 😊
Ok mam Thank you ☺️
You haven't incremented the while loop....Is it auto incremented..Can you explain in detail
Mam can u please do vedios on solving problems in python data structures
Will try 😊
Beautifully explained :)
what if in a linked list duplicate data are present....can we add the node on the basis of index numbers like we do in a list
Yes you can:)
@@AmulsAcademy pls make a video on that ma'am...
Noted :)
Thanks for this video
Welcome :)
Mam you're awesome
Thank you :)
can we do while "n.ref" is not None while iterating to last node?
Which language should i choose to learn DS and Algo?
C :)
@@AmulsAcademy Mam but u have made DSA series in python if i learn in C will i be able to understand ur series. Can u recommend any Books
@@bhupendravyas6213 then you need to master pointer😂
Easy to understand but sometime creats confusion😎
Who will tell u that previous node value by which u would traverse till that nd insert after that. Bcoz u will be given a linked list nd just position will be given to u not previous node data value. Bcoz to access previous node data value u have to traverse uptill that otherwise how can u get that? Here u know it’s 100 beforehand That's why u r using that but in real scenerio if any other will make the list nd tell u to insert a element in a certain position then how can u do that??
I think we can take a counter here nd increment that till before the mentioned position like if position 3 increment that counter till 2, like
Count = 0
n = New_node
While count
Superb
tysm dear!
perfect
Thank you :)
Please give me the book name where you learned 🙏
I didn’t refer any particular book :)
getting runtime error for the code
Good tutorial 👍
Question :-
What happen if link list contain dublicate number ?
Eg :-
5,5,5,15
Now I want to add 1000 number after 2nd 5 of index 1.
5,5,___HERE___,5,15
Please help
How does python store the address ?
Object, Python is all about object even if you are defining a function then at the time of calling you are making an object.
So, in other word object is like an address/reference of that particular node or function or class.
Example
def fun():
print("hello")
a = fun()
a()
So, in above example when fun() is called then it actually creats an object and that object is now assigned to 'a' and with the help of that object you again called the same function fun()
Anyone is welcome to improve my explanation
@AmulsAcademy it is good to learn data structures in python for top company placements
insert value by index
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.len = 0
def view(self)-> str:
string = "["
if self.head is None:
return "[]"
else:
while self.head is not None:
string += f"{self.head.data}, "
self.head = self.head.next
return string[:-2] + "]"
def insert(self, data: any):
if self.head is None:
self.head = Node(data)
self.len += 1
else:
new_node = Node(data)
new_node.next = self.head
self.head = new_node
self.len += 1
def append(self,data: any):
if self.head is None:
self.head = Node(data)
self.len += 1
else:
n = self.head
while n.next is not None:
n = n.next
n.next = Node(data)
self.len += 1
def insert_at(self, data: any, index: int)-> None:
n = self.head
count = 0
if index > self.len:
print(f"Error: Can not add data into position {index}")
elif index == self.len:
self.append(data)
elif index == 0:
self.insert(data)
else:
while n is not None:
if count == (index-1):
new_node = Node(data)
new_node.next = n.next
n.next = new_node
self.len += 1
n = n.next
count += 1
LL = LinkedList()
LL.insert(5)
LL.insert(10)
LL.append(15)
LL.insert_at(29,2)
print(LL.view())
osm osm osm osm osm
nice video, thank you
mam please create class 12 th playlist for boards
Nice voice
The code that you are showing here is not working as it is, suppose your LinkedList is 10 -> 20 -> 30 ->40, and you have to add node after 20, then the print_ll() will not print the first node(10). Code is note working properly, My code is.
class Node():
def __init__(self,data):
self.data=data
self.ref=None
class linkedlist():
def __init__(self):
self.head=None
def print_ll(self):
if self.head is None:
print("Linkedlist is empty")
else:
while self.head is not None:
print(self.head.data, "--->",end=' ')
self.head=self.head.ref
def add_begin(self,data):
new_node=Node(data)
if self.head is None:
self.head=new_node
else:
new_node.ref=self.head.ref
self.head=new_node
def add_at_end(self,data):
new_node=Node(data)
if self.head is None:
self.head=new_node
else:
while self.head.ref is not None:
self.head=self.head.ref
self.head.ref=new_node
def add_in_between(self,data,afternode):
while self.head is not None:
if afternode==self.head.data:
break
self.head=self.head.ref
if self.head is None:
print("Item is Not present in list")
else:
new_node=Node(data)
new_node.ref=self.head.ref
self.head.ref=new_node
l=linkedlist()
l.add_begin(25)
l.add_at_end(30)
l.add_begin(20)
l.add_at_end(90)
l.add_begin(1)
l.add_at_end(1800)
l.add_in_between(1000,20)
l.print_ll()
But program is working correctly when I add another node after 20 😊
👍
Thank you :)
So many nodes makes this confusing 😅
Using a website like pythontutor and adding the code (which you can find in the description of the previous linked list videos up to now) might make it clear. It goes through every step of the code and shows exactly what it does with diagrams. That's what I'm using. Best of luck in your studies and work.
confusing