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🙏
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.
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
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.
*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.
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.
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); }
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; }
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, 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?
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.