This is the hands-down BEST VIDEO I've found on internet explaining linked-lists. All videos from other people only use 2 nodes and that leaves no possibility of automating head->next = temp in while loop. You'd have to write manually such as head->next = temp, head->next->next = temp and so on. Using a 3rd node p really solved my problem on which I was stuck for quite long time. You're the best. THANK YOU VERY MUCH.
Sir you're really one of the best tutor I've ever seen..... I regularly follow you and recommended your channel to all my college mates.... keep uploading more contents for students like us. May god bless you
best linked list implementation program ever explained every point in detail and I was try to do for about 3 day. and now every thing is cleared really thanks
Thank you so much! I was stuck in linked list. I got savior like you really if teachers will teach and explain each and everything like you DSA won't be boring. Again Thank you🙏
finally you save me from cramming! I'm used to head being a global variable so when the prof provide assignment that making the head as local variable, that's where i stuck up to
I was very happy yesterday that I found your channel but after that I saw many videos i want are not there😓 It's ok I'm not blaming you sir it's just that I loved your teaching.
In a linked list, whenever you add a new node, there is no point adding it to the end of the list. This makes the operation O(n) which can take a very long time when you are adding your 1 millionth element to the list. Inserting a new node and attaching it to the former head and then defining it as the new head, takes a lot less time, O(1). If you do this, your list is reversed and checking whether an element is in the list or printing all the data in the nodes will take just as much time.
Am I the only one seeing a mistake in the printf argument??? The code should not compile, I mean, I do not like when someone hides his mistakes just to make everything seem perfect.
I don't think it is absolutely necessary to iterate the existing list to attach to a new node to the last node. A simple node pointer variable, say "node *previous" can be used for this purpose in the else clause, thus: if(head == NULL) { ... } else { previous->next = temp; } Then at the end of the for loop the following assignment will ensure that "previous" is assigned a valid value for subsequent iterations and therefore, keeps track of the last created node for(...) } .... previous = temp; }
here is the exact code,hope this helps . . #include #include struct node{ int data; struct node*next; }; void displaylist(struct node*head); struct node *createlinkedlist(int n); int main() { int n=0; struct node* HEAD=NULL; printf(" how many nodes:"); scanf("%d",&n); HEAD=createlinkedlist(n); displaylist(HEAD); } struct node *createlinkedlist(int n)//function to create a single ll and add to end { int i; struct node*head=NULL; struct node*temp=NULL; struct node*p=NULL; for(i=0;idata)); temp->next=NULL;
if(head==NULL) //if head is empty make temp as first node { head=temp; }
*node.data is the same as node->data. The dereference operator (*) is used to retrieve the actual node instead of the memory address (since node here is a pointer). Then dot notation to access variables in that node struct. The arrow operator (->) combines those two steps into one.
sir, this is very inefficient. u keep setting p back to head instead of keeping it at the end of the list. can you please make a tutoriol to make a more efficient list perhaps?
I keep getting an error warning: data argument not used by format string for printf(" Enter the data for node number:", i+ 1); I don't know how to fix this
My head node changes with every iteration, even after the first. It only does the if statement once but if temp changes so does head. How do you fix this?
Does the while loop in the createLinkedList function operate? I mean since it is always false? Because p is always set to head, and head has always head->next = NULL.
if i want to count node can i use this code?: void getcount(node*head){ int count=0; struct node*current; current=head; while(current!=NULL){ count++; current=current->next; } printf("the lenght of the train is:%d",count); return count; } in main () { getcount(HEAD); }
Sir i executed this code and it is taking inputs(valur of nodes) correctly but when its the time of display then it is showing an infinite loop....plzz help
Sir please say that why you used node* in node* createLinkedList(int n)....and also explain that why you only returned head as it contain only th value of head..Please explain that sir..
you can return pointers with functions the createlinkedlist is type node* because it returns a pointer to the struct node* structs are still data types they're just "complex" because they can contain int's, char's, etc, so you can't use an int pointer to a struct, you'd have to use a pointer which is of type struct (name of the struct) linked lists only need the starting value as in the function where the program creates it, it also iterates through them and changes the value of them in each { p = head; while(p->next_node != NULL) { p = p->next_node; } p->next_node = temp; p is just a pointer for iteration, so it's used to go through the list til it finds the last item, if there is one, it would change the value of the "next" to temp, because temp is a pointer to the last node so you don't need the individual address of each node saved, like you would with an array
@@Babu-rj6ll the struct has a pointer called next when you make a new node you also cycle through them, and change that next value to the new one (aka temp, which stores the address of the new node), so all you need is the address of the first node which is pretty much contained in the head it's how a linked list functions, you have to go through each of them to get to the part of the list you want
What if we replace code line int data with line An_element data where An_element is a struct and it has a single member int integer. If I do it in your code I see exception on line temp=(node*)malloc(sizeof(node)). I m trying to learn struct use on a list like this.
This is the hands-down BEST VIDEO I've found on internet explaining linked-lists. All videos from other people only use 2 nodes and that leaves no possibility of automating head->next = temp in while loop. You'd have to write manually such as head->next = temp, head->next->next = temp and so on.
Using a 3rd node p really solved my problem on which I was stuck for quite long time.
You're the best. THANK YOU VERY MUCH.
Sir you're really one of the best tutor I've ever seen..... I regularly follow you and recommended your channel to all my college mates.... keep uploading more contents for students like us. May god bless you
Great explanation. I like that you walk through the code step by step. It really helped me understand how linked lists work.
I was serious during the whole program. But when he said that this is a simple program, i laughed .
I understand bro 😏
hahahahaha
lol
best linked list implementation program ever explained
every point in detail and I was try to do for about 3 day.
and now every thing is cleared
really thanks
Thank you! This was one of the best explained tutorials I've seen so far:) very helpful
Oh my! Thank you! I've been racking my brain how to get this to work.
Happy to help!
Mere teacher se accha sikhya aapne sir 3 din se sar fod raha tha me aaj finally ek perfect video mila jo dekh kar samaj me aya thanks sir
probably the best explanation of ow to create a linked list
thanku so much sir for the clear explaination am searching for this type of video only where i can understand from basics.
FINALLY AN ACTUAL GOOD VIDEO ON THIS TOPIC THANK YOU KING
Thank you so much! I wonder why my college teacher couldn't explain like this
This is absolutely the best video of linked list for beginners
Thank you so much! I was stuck in linked list. I got savior like you really if teachers will teach and explain each and everything like you DSA won't be boring. Again Thank you🙏
finally you save me from cramming! I'm used to head being a global variable so when the prof provide assignment that making the head as local variable, that's where i stuck up to
I was very happy yesterday that I found your channel but after that I saw many videos i want are not there😓
It's ok I'm not blaming you sir it's just that I loved your teaching.
Thank you sir , I was understanding nothing on linked list . Big thanks to your video
Your explanation is top-notch! Thanks a lot!
In a linked list, whenever you add a new node, there is no point adding it to the end of the list.
This makes the operation O(n) which can take a very long time when you are adding your 1 millionth element to the list. Inserting a new node and attaching it to the former head and then defining it as the new head, takes a lot less time, O(1). If you do this, your list is reversed and checking whether an element is in the list or printing all the data in the nodes will take just as much time.
Am I the only one seeing a mistake in the printf argument??? The code should not compile, I mean, I do not like when someone hides his mistakes just to make everything seem perfect.
Woow nice. I think I learned linked list with 3 videos and ur video is the bigest step.
Best tutorial for LINKED LIST IN C !!!!!!!!!!!!!!!!!!!!!
the best !
Thank you so much sir. Was stuck on this for quite a long time.
awsome sir i had sarched many website but i didn't find tq sir
Great explanation. Although I wish you used curly braces on that while loop...took me a day to realize next line is outside of the loop
Thanks a lot! It was very helpfull. Salutations from Brazil
Great explanation. I understood linked list very well
Glad it was helpful!
just great explanation thank you a lot sir this was very helpful
Glad it was helpful!
THANK YOU . YOU LITERALLY SAVED ME BRO
Or we can use do while loop to successfully print the last node using logic condition (p->next != NULL)
Thank you sir for well explanation.
Sir I want lecture of data structure
Please help me.
Awesome explanation... Thanks you very much ✅
Thanks for the video, one of the understandable video I've ever seen about linkedl list
Thank you for explaining the code so neatly....♥️
Hiii
Thank you! it was very helpful.
Good explanation.Thank you!
Thank you so much for this. You helped me a lot.
Glad I could help!
sir ap k lactures bhut a6y han
add more lactures in linked list all operation
Surely, that is on the agenda. Will be doing that soon.
@@BBarters thaks you sir
I don't think it is absolutely necessary to iterate the existing list to attach to a new node to the last node.
A simple node pointer variable, say "node *previous" can be used for this purpose in the else clause, thus:
if(head == NULL)
{
...
}
else
{
previous->next = temp;
}
Then at the end of the for loop the following assignment will ensure that "previous" is assigned a valid value for subsequent iterations and therefore, keeps track of the last created node
for(...)
}
....
previous = temp;
}
Bhai ye code detail mai likho na pls
here is the exact code,hope this helps
.
.
#include
#include
struct node{
int data;
struct node*next;
};
void displaylist(struct node*head);
struct node *createlinkedlist(int n);
int main()
{
int n=0;
struct node* HEAD=NULL;
printf("
how many nodes:");
scanf("%d",&n);
HEAD=createlinkedlist(n);
displaylist(HEAD);
}
struct node *createlinkedlist(int n)//function to create a single ll and add to end
{
int i;
struct node*head=NULL;
struct node*temp=NULL;
struct node*p=NULL;
for(i=0;idata));
temp->next=NULL;
if(head==NULL) //if head is empty make temp as first node
{
head=temp;
}
else
{
p=head;
while(p->next!=NULL)
p=p->next;
p->next=temp;
}
}
return head;
}
void displaylist(struct node*head)//function to display code
{
struct node*z=head;
while(z!=NULL)
{
printf("%d->",z->data);
z=z->next;
}
}
note-i did not use typedef because i prefer using struct node instead of node.
sir please could you do Data Structures in one video....or maybe a playlist....especially with respect to interview
Sir, yr explaining way is perfect 🤗
Good explanation sir thanks.
You are welcome!
is * and -> the same thing in c?
*node.data is the same as node->data. The dereference operator (*) is used to retrieve the actual node instead of the memory address (since node here is a pointer). Then dot notation to access variables in that node struct. The arrow operator (->) combines those two steps into one.
Thx 🙏🏻 @@djankies
p->data is the same as (*p).data
Thanks a lot ! You help me very much!
This really helped me !
you be smashing that keyboard
Thank you! The vedio help me a lot.
Awesome explaination
Glad you liked it!
This is really helpful!
sir, this is very inefficient. u keep setting p back to head instead of keeping it at the end of the list. can you please make a tutoriol to make a more efficient list perhaps?
you did what my professor couldn't.......
R.I.P to keyboard keys.....btw nice explanation
very nice tutorial.
Ahhh, I finally got what I did wrong! Thank you man!
I keep getting an error warning: data argument not used by format string for printf("
Enter the data for node number:", i+ 1); I don't know how to fix this
Add %d after the number word
Thanks for the tutorial!
thank's broo, it was helpful
You're welcome!
Sir, can you show me how to read values from struct manual input and passing a pointer containing name, id and cgpa to linked list. Thank you.
Which software you use for c programming
it's CLion
My head node changes with every iteration, even after the first. It only does the if statement once but if temp changes so does head. How do you fix this?
best till date.....
Thank you , nice explanation!
i will not write a long comment but ,
thank you SO MUCH for this...
You're very welcome!
Thankq Sir, this help me a lot.
Does the while loop in the createLinkedList function operate? I mean since it is always false? Because p is always set to head, and head has always head->next = NULL.
Hey did you get the answer. Please tell me tok
*too
@@tanyasingh4421 yes
Don't u like, free the memory for LinkedList?
sir could you please cover trees concept
Man wish i found this video when i was taking data structures 8 years ago, maybe i wouldnt have switched to a useless physics degree
if i want to count node can i use this code?:
void getcount(node*head){
int count=0;
struct node*current;
current=head;
while(current!=NULL){
count++;
current=current->next;
}
printf("the lenght of the train is:%d",count);
return count;
}
in main () {
getcount(HEAD);
}
Hi Sir, how can we do to delete the particular node. Any video of yours? Appreciate on it =)
is there a video about operations of linked lists like insert delete on your chanel?
i will share this with my friends
are you able to add stuff to the linked list in the console?
Thank You so much
Thanks a lot sir
great sir
where can i get a video where a character is used instead of integer data to make a linked list
Thank you so much ❤️
You’re welcome 😊
Nice video. Which IDE are you using?
Sir i executed this code and it is taking inputs(valur of nodes) correctly but when its the time of display then it is showing an infinite loop....plzz help
This stuff is so complex for a beginner, my prof acts like its nothing.
finally.....thank u so much sir
very good...
thanks for this video sir
It helped me a lot
but sir when i written same code the erron was comming at this line
node* creareList(int n)
the error is conflicting type error what should i do
Awesome Video... Which IDE are you using on your MacBook?
Ariq Ahmer I think it's xcode
Golu.chotu Shukla thanks... I'll look into it
Sir please say that why you used node* in node* createLinkedList(int n)....and also explain that why you only returned head as it contain only th value of head..Please explain that sir..
you can return pointers with functions
the createlinkedlist is type node* because it returns a pointer to the struct node*
structs are still data types they're just "complex" because they can contain int's, char's, etc, so you can't use an int pointer to a struct, you'd have to use a pointer which is of type struct (name of the struct)
linked lists only need the starting value as in the function where the program creates it, it also iterates through them and changes the value of them in each
{
p = head;
while(p->next_node != NULL)
{
p = p->next_node;
}
p->next_node = temp;
p is just a pointer for iteration, so it's used to go through the list til it finds the last item, if there is one, it would change the value of the "next" to temp, because temp is a pointer to the last node so you don't need the individual address of each node saved, like you would with an array
@@ale-hl8pg But why is head enough to return
@@Babu-rj6ll the struct has a pointer called next
when you make a new node you also cycle through them, and change that next value to the new one (aka temp, which stores the address of the new node), so all you need is the address of the first node which is pretty much contained in the head
it's how a linked list functions, you have to go through each of them to get to the part of the list you want
very helpful thank you
thank you so much!
theres a way to rank those numbers in crescent order?
Hi Sir which compiler you are using?
Thank you!!!
do we need to free the memory with free()?
Very informative, thanks! However you used malloc, without freeing up the allocated memory at the end.
This function will fix that:
void freeMemory(node * head)
{
node * p = head;
node * temp = NULL;
while (p != NULL)
{
temp = p;
free(p);
p = temp->next;
}
}
What if we replace code line int data with line An_element data where An_element is a struct and it has a single member int integer. If I do it in your code I see exception on line temp=(node*)malloc(sizeof(node)). I m trying to learn struct use on a list like this.
Write a function that is used to read 5 student marks and store them using
Linked List.
I write this code and when I tried my output was 1-> 2-> 33->9772504... My input was 1,2,33. Why 9772504 occurs in my code. Can anybody help?
Because it overflows the integer, the max number you can use is 32,767 or twice if it's an unsigned int
Thank you