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.
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
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
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.
*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.
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?
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
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); }
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; }
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
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.
why we write the node * createLinkedList (int n); line? as we are not creating a function with that line. we again have to write it below and then also specify instructions in the function. what is the need of the earlier line.
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
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.
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.
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
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
I was serious during the whole program. But when he said that this is a simple program, i laughed .
I understand bro 😏
hahahahaha
lol
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.
Thank you! This was one of the best explained tutorials I've seen so far:) very helpful
This is absolutely the best video of linked list for beginners
FINALLY AN ACTUAL GOOD VIDEO ON THIS TOPIC THANK YOU KING
thanku so much sir for the clear explaination am searching for this type of video only where i can understand from basics.
Oh my! Thank you! I've been racking my brain how to get this to work.
Happy to help!
probably the best explanation of ow to create a linked list
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🙏
Best tutorial for LINKED LIST IN C !!!!!!!!!!!!!!!!!!!!!
the best !
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
Thank you so much! I wonder why my college teacher couldn't explain like this
Woow nice. I think I learned linked list with 3 videos and ur video is the bigest step.
Thank you sir , I was understanding nothing on linked list . Big thanks to your video
Your explanation is top-notch! Thanks a lot!
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 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
THANK YOU . YOU LITERALLY SAVED ME BRO
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.
Great explanation. I understood linked list very well
Glad it was helpful!
are you able to add stuff to the linked list in the console?
Thanks a lot! It was very helpfull. Salutations from Brazil
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
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?
Awesome explanation... Thanks you very much ✅
just great explanation thank you a lot sir this was very helpful
Glad it was helpful!
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 video, one of the understandable video I've ever seen about linkedl list
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
do we need to free the memory with free()?
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
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
Good explanation sir thanks.
You are welcome!
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);
}
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.
Which software you use for c programming
it's CLion
Awesome explaination
Glad you liked it!
Or we can use do while loop to successfully print the last node using logic condition (p->next != NULL)
Sir, yr explaining way is perfect 🤗
Hi Sir which compiler you are using?
theres a way to rank those numbers in crescent order?
Thank you sir for well explanation.
Sir I want lecture of data structure
Please help me.
Good explanation.Thank you!
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.
do we have to free malloc?
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
you did what my professor couldn't.......
謝謝,我有疑問使用malloc怎麼沒使用free
Don't u like, free the memory for LinkedList?
best till date.....
is there a video about operations of linked lists like insert delete on your chanel?
Thank you! it was very helpful.
Thank you for explaining the code so neatly....♥️
Hiii
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
This really helped me !
This is really helpful!
where can i get a video where a character is used instead of integer data to make a linked list
Thank you so much for this. You helped me a lot.
Glad I could help!
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.
Hi Sir, how can we do to delete the particular node. Any video of yours? Appreciate on it =)
you be smashing that keyboard
very nice tutorial.
Thank you! The vedio help me a lot.
sir please could you do Data Structures in one video....or maybe a playlist....especially with respect to interview
Thanks a lot ! You help me very much!
Amazing🥰
i will share this with my friends
R.I.P to keyboard keys.....btw nice explanation
Ahhh, I finally got what I did wrong! Thank you man!
Where did the other videos go?
Sir r u running any institute.
thank's broo, it was helpful
You're welcome!
why we write the node * createLinkedList (int n); line? as we are not creating a function with that line. we again have to write it below and then also specify instructions in the function. what is the need of the earlier line.
Soham Zemse it is a function prototype to declare a function.
Sir youre best
Nice video. Which IDE are you using?
Thanks for the tutorial!
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
sir could you please cover trees concept
i will not write a long comment but ,
thank you SO MUCH for this...
You're very welcome!
哈哈哈謝謝,我知道我錯在那了8:28,我把while(p->next!=NULL){p=p->next; p->next=temp;}寫在一起,抱歉抱歉
i tried the same code but it showing segmentation fault
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
Where you have declared struct node
finally.....thank u so much sir
What happens if you need an empty list?
For me it's not printing the last number, for example i input the number 5,6,8,7,4 and it prints 5->6->8->7
Anyone help?
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
thanks for this video sir
great sir
Thank you , nice explanation!
very good...
Excellent Sir
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
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.
Thankq Sir, this help me a lot.