Тёмный

Linked List in C/C++ - Inserting a node at beginning 

mycodeschool
Подписаться 769 тыс.
Просмотров 1,2 млн
50% 1

Опубликовано:

 

25 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 579   
@youssefrezkou7003
@youssefrezkou7003 5 лет назад
after 6 years of creating this videos ... no one created something better ! thanks alot teacher
@bipulkumar6637
@bipulkumar6637 3 года назад
Sadly we dont have the founder of this channel
@ayushsharma9640
@ayushsharma9640 3 года назад
@@bipulkumar6637 yes he is no more
@Critiquetech
@Critiquetech 3 года назад
Is he Lord Harsha?
@psibarpsi
@psibarpsi 2 года назад
@@Critiquetech The one teaching in this video is Animesh Nayan. Harsh also has a video on this channel - the one about GCD algorithm.
@thestarinthesky_
@thestarinthesky_ 4 года назад
The most AMAZING course explained brilliantly! So grateful!
@mycodeschool
@mycodeschool 11 лет назад
Hi Siddharth, Yes, we will continue creating more videos in data structures series. :)
@girishmehra8383
@girishmehra8383 4 года назад
sir, please make video series on dynamic programming, greedy Algorithms,divide and conquer etc and some advance data structures like segment trees !!
@convolutionalnn2582
@convolutionalnn2582 4 года назад
Numbers inputs from users display on List: are joint and no space between them why?
@sharonjoe7535
@sharonjoe7535 3 года назад
@@convolutionalnn2582 use endl for c++ or newline character for C
@mycodeschool
@mycodeschool 11 лет назад
Yes, that's true. You should free any memory allocated using malloc once you are done using it. In this lesson, the intent was to show the implementation of insert function. But despite that, not having an explicit free is not doing any bad here. As soon as we are done printing all the elements, we are anyway done in the main function and the program execution will finish. And once program finishes, all of its memory is freed anyway.
@caojinguo3043
@caojinguo3043 2 года назад
Thank you for your patience, I have always had doubts here
@AkshayKumar-dz5ts
@AkshayKumar-dz5ts 8 лет назад
For anybody getting the error "node not defined" -> after initial definition of the node and before the semicolon just put Node it looks something like this struct Node { int data; struct Node* next; }Node; If anybody wants the whole code to the one in this lesson: //INSERTION OF NODES AT THE BEGINNING AND IT'S DISPLAY #include #include struct Node { int data; struct Node* next; }Node; struct Node* head; void insert(int x); void print(); void main() { head=NULL; printf("how many numbers? "); int n,i,x; scanf("%d",&n); for(i=0;idata=x; temp->next=head; head=temp; } void print() { struct Node* temp=head; printf("List is:"); while(temp!=NULL) { printf("%d ",temp->data); temp=temp->next; } printf(" "); }
@prachalaugustine9651
@prachalaugustine9651 6 лет назад
Akshay Kumar Thanks a ton buddy
@syedawardha2351
@syedawardha2351 6 лет назад
Akshay Kumar i
@joydeepbhattacharjee5305
@joydeepbhattacharjee5305 5 лет назад
thanks bro it was helpful for me
@riefkymaulana9040
@riefkymaulana9040 5 лет назад
thanks bro
@aaradhanah5059
@aaradhanah5059 5 лет назад
thanks brother
@rohitaswasarbhangia7722
@rohitaswasarbhangia7722 7 лет назад
the way you changed the implementation, one using global variable, others using return and pointer to pointer, dope sir. now I know how proficient I need to be to just participate in competitive programming. thanks again.
@ramanjangu895
@ramanjangu895 Год назад
quality of content is amazing ,I am just started learning from this playlist.
@Gaggio23
@Gaggio23 9 лет назад
Even if you are programming in C you can avoid to write "struct Node ..." every time by declaring the struct like this: typedef struct Node{ int data; struct Node* next; }Node; This way you will be able to declare Node variables the same way you do in C++.
@anfield6321
@anfield6321 7 лет назад
He assumes that people are fairly new to c because of which he wants to make the code as simple as possible
@theamjolnir9641
@theamjolnir9641 6 лет назад
Ahaa!!!
@andremuslim9594
@andremuslim9594 6 лет назад
That's great man. Thanks a lot
@StockDC2
@StockDC2 6 лет назад
Just as an FYI for anyone looking into doing this, this polutes the global namespace and is not recommended.
@markd2797
@markd2797 5 лет назад
Is there a way to do this without malloc? Because I am fairly new and I have no idea what malloc is.
@MrAkshatmahajan
@MrAkshatmahajan 6 лет назад
better than books,teachers,those udemy courses. You are the best. These tutorials will never get outdated.
@mycodeschool
@mycodeschool 11 лет назад
Your insertion logic is correct. You may have a bug in main or print functions. Try to debug. Print your list every-time you insert a new element. So like after every call to insert_node, make a call to print. You should be able to nail down the exact issue.
@GabrielSousathe
@GabrielSousathe 6 лет назад
THANK YOU, JUST, THANK YOU! Your work is amazing, your videos are great and the way you teach is just incredibly good. I really appreciate what you have done and have been doing.
@tuongdihoc
@tuongdihoc Год назад
Amazing, this is the first time that I realize the beauty of pointer!
@AJAYLIKEEMO
@AJAYLIKEEMO 4 года назад
This was my most daunting concept. It took me 3 hours to understand this but at last I did it.
@NitishKumarTutorials
@NitishKumarTutorials 4 года назад
Watch this one , it is the best seedha dimag mein ghusegaa sara doubt clear ru-vid.com/group/PLbRk-vKGcVtbyctZWP9SUYewwUfx75CpZ
@lovishdhingra801
@lovishdhingra801 4 года назад
@@NitishKumarTutorials thankyou sir
@AjaySharma-le3df
@AjaySharma-le3df 4 года назад
Thank you so much. I finally understood this after watching it so many times. You guys are doing great work.👍🏽
@abhishekagarwal3852
@abhishekagarwal3852 4 года назад
Lockdown ka poora productive utilization ho raha hai bhai. Ek number bhai aise hi laga reh.
@AjaySharma-le3df
@AjaySharma-le3df 4 года назад
@@abhishekagarwal3852 😁😁 same to you bro🙏🏼
@jamesbones1668
@jamesbones1668 7 лет назад
i think you're the best when it comes to c-related material, dude. thanks.
@license2Bort
@license2Bort 9 лет назад
Exceptional video man. I was in a complete blank about how to do a linked list, but this video explained everything perfectly. Thank you.
@Rishabh2352
@Rishabh2352 7 лет назад
Best content on Internet for learning data structures. Great work. Thanks a lot.
@khedubaba
@khedubaba 6 лет назад
After 9:50 , No thanx I'll keep my head global.
@kunalkumar2717
@kunalkumar2717 4 года назад
OO BHAI....
@ambujsingh3844
@ambujsingh3844 4 года назад
😂
@ujjawal.pandey
@ujjawal.pandey 3 года назад
Tru that bruh!😂😂
@shivamverma9447
@shivamverma9447 3 года назад
yes bro, i m with you
@ritinkarmalakar350
@ritinkarmalakar350 3 года назад
Lol..
@mycodeschool
@mycodeschool 11 лет назад
I was using a C++ compiler. You do not need to write struct keyword in C++. Moreover, this thing is testing whether someone running this code in C can debug simple compilation errors or not. :) Anyway, thanks for noticing.
@madaxe8894
@madaxe8894 4 года назад
Best data structure course on earth.
@opc816
@opc816 10 лет назад
No joke he is the best. He makes everything so clear. Thank you so much sir
@crazymexicandope
@crazymexicandope 6 лет назад
12:08 I was taking a drink when he said it, I almost drowned! Lol
@saketkumar7335
@saketkumar7335 4 года назад
very stupid
@HARIHaran-ks7wp
@HARIHaran-ks7wp 4 года назад
lmaooooo good one
@aqibsuhail8388
@aqibsuhail8388 3 года назад
Lmaoo
@freddyflores6608
@freddyflores6608 6 лет назад
The best video of Linked List I've ever seen, a good way to explain programming :) .
@divyadeb123
@divyadeb123 10 лет назад
YOU, sir, are a life savior !!!!!!!!!!!!!!!!!!
@sharonjoe7535
@sharonjoe7535 3 года назад
You code for work or as a hobby🤔😂
@balajivaasan9532
@balajivaasan9532 5 лет назад
After all happy to see a video in english -a non hindispeaker
@lamebrisee
@lamebrisee 4 года назад
best teacher ever . you healed my pointers trauma ;-)
@MrPatex21
@MrPatex21 11 лет назад
I just wanted to point it our for someone who would have the same problems as me. Btw very good tutorials and this one is the first that I'll have to watch a couple more times to completly understood.
@mashable8759
@mashable8759 8 лет назад
35 dislikes are those people who use ARRAY all the time XD
@manishbudhathoki892
@manishbudhathoki892 7 лет назад
hahaha maybe
@anfield6321
@anfield6321 7 лет назад
Well linked list is not efficient to use at all. We should avoid using linked list as much as possible
@ffantasyvii
@ffantasyvii 7 лет назад
Why is that, and if so what is the most efficient way?
@rolandoaguilera3114
@rolandoaguilera3114 6 лет назад
For RTOS (Real Time Operating Systems) linked lists are fundamental
@pathfinder750
@pathfinder750 6 лет назад
Umm i think it depends on what you're working with
@vasilvasilev7938
@vasilvasilev7938 10 лет назад
I love your lessons! Can you please also upload c++ code implementation?
@kanicagoddard6330
@kanicagoddard6330 3 года назад
#include using namespace std; struct Node { int data; Node* next; }; Node* head; void insert(int ind_input) { Node* temp = new Node; temp -> data = ind_input; temp -> next = head; head = temp; }; void print() { Node* temp = head; while(temp != nullptr) { cout data next; } cout user_input; int ind_input; for(int i = 0; i < user_input; i++) { cout > ind_input; insert(ind_input); print(); }; };
@sulabhthephenomenalone4343
@sulabhthephenomenalone4343 3 года назад
@@kanicagoddard6330 thank youu
@mycodeschool
@mycodeschool 11 лет назад
Thanks Jason !
@Shagawee
@Shagawee 10 лет назад
Thank you for these tutorials! They make the concepts of coding way easier to grasp.
@ManojKumar-bz7qm
@ManojKumar-bz7qm 6 лет назад
your explanation is just awesome sir..keep it doing
@suryasahu9046
@suryasahu9046 7 лет назад
Loved the call by reference used in insert function by you at the end where you change the value of memory reference of insert var by passing address of insert
@mahesh_jamdade
@mahesh_jamdade 8 лет назад
thank you very much for this video,I was struggling a lot to understand how lists were implemented in c Even my teachers failed to make me Understand thanks a lot. you know what Iam posting this comment after implementing the lists successfully thank a lot.👍
@manjeetsinghmehta9462
@manjeetsinghmehta9462 8 лет назад
awesome ...this is what i was in search of ......very helpful to clear basic understanding ....thanks buddy....
@unsaturated8482
@unsaturated8482 7 лет назад
you make great videos sire. Thank you for all your efforts. I love your desire to help people. you're a real man.
@GaganDeep-xz8kf
@GaganDeep-xz8kf 4 года назад
sir thaxxx a lot ,your efforts are are priceless
@supertran28
@supertran28 7 лет назад
You have saved my grade in college. Thank you so much
@randomvinesvids5703
@randomvinesvids5703 9 лет назад
Complete code for: Insertion, Deletion and Print working: #include using namespace std; struct Node{ int data; Node* next; }; Node* Insert(Node* head, int x) { Node* newN=new Node(); newN->data=x; newN->next=NULL; if(head!=NULL) newN->next=head; head=newN; return head; } Node* InsertNth(Node* head, int x, int nt) { Node* temp1=new Node(); temp1->data=x; temp1->next=NULL; if(nt==1) { temp1->next=head; head=temp1; return head; } Node* temp2=head; for(int i=0; inext; } temp1->next=temp2->next; temp2->next=temp1; return temp2; } Node *DeleteNth(Node* head, int nt) { Node* temp1=head; if(nt==1){ head=temp1->next; delete temp1; return head; } for(int i=0; inext; } Node *temp2=temp1->next; temp1->next=temp2->next; delete temp2; return temp1; } void Print(Node* head) { while(head!=NULL) { cout
@muhammadsajjad9769
@muhammadsajjad9769 3 года назад
Love u Sir Best teacher ever
@moongirl26cac
@moongirl26cac 10 лет назад
Thank you ,this clarified a lot of things for me..
@barakode414
@barakode414 4 года назад
I always struggle to understand about linked list and pointer. I got my aha moment because of this video and the previous one about linked list in c/c++. Thank you
@s.baskaravishnu22
@s.baskaravishnu22 6 лет назад
your videos are excellent. Your videos are very much useful to me, Many thanks for that. My warm regards to you.
@sid1501
@sid1501 11 лет назад
thanks a lot for your videos! they helped me a great deal!!! can you please continue making more ? like for stacks, queues, double linked list! it would be really helpful thanks!!
@SamsungJPro-qo2cn
@SamsungJPro-qo2cn 4 года назад
You solved my problem . Thanku so much sir
@tushargoel5522
@tushargoel5522 11 лет назад
Thanks for quick response..I resolved the issue. I forgot to initialize the struct to the starting point before printing it.. I spend several hours on ths but havent care abt it earlier.
@usama57926
@usama57926 6 лет назад
great explanation
@satviknema8629
@satviknema8629 6 лет назад
LoL the last 30 seconds were MINDFUCK great content btw, it is really helpful!! :D
@NJM0901
@NJM0901 7 лет назад
Thank you so much ....😁.... It helped me lot .... I am gonna rock my lab test ....💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙💙
@dhananjaykumarpal1604
@dhananjaykumarpal1604 6 лет назад
Thanks.... Great way of teaching. 🙏🙏🙏🙏
@Dhyanithamanavya
@Dhyanithamanavya 7 лет назад
who would be scared of programming or hate it if someone is teaching so well like this..
@shashanks7346
@shashanks7346 2 года назад
Miss U legend !
@Nj01lyon
@Nj01lyon 8 лет назад
Thanks! Now i get the real scenario of link list
@sr5726
@sr5726 9 лет назад
Thank you for the video. Print function can also have null check for empty list if (head == NULL) { cout next = head; head = newNode; } InsertBeginning(head, 300);
@tanujadon
@tanujadon 4 года назад
Thankyou so much for this video.. i have finally found everything in a video as i was very confused with this head variable being declared different everywhere.
@sanjitjena4954
@sanjitjena4954 Год назад
The perils of C! My memories of high school C are rather less convoluted.
@_thoneeer3220
@_thoneeer3220 6 лет назад
OMG. Are you GOD of pointer? How can you understand pointer so fucking well... It was so cooooooooooooooooooooolllllllllllllllll. BTW, thank you ....
@coolsoft3176
@coolsoft3176 6 лет назад
Thanks for the lesson its really helping me to usderstand the concept of linked list
@kathirs1
@kathirs1 8 лет назад
Awesome video I have ever seen...good job !!!
@srkrohit
@srkrohit 9 лет назад
Thank you so much for the video. Very nicely explained.
@agrawalsweety3961
@agrawalsweety3961 10 лет назад
please upload boolean algebra if posiible as soon as possible....... and your videos are just awesome..thanks a lot....
@yathishkumary7793
@yathishkumary7793 4 года назад
Sir your video explanation is awesome 👌👌. Please🙏🙏 Kindly Tell me where you learnt all these concepts please suggest me
@drsaluto
@drsaluto 8 лет назад
Thanks a lot here. I have gotten my itch sorted. Thank you loads.
@anishabhatnagar1839
@anishabhatnagar1839 8 лет назад
thank you!! this is awesome and it clears all my doubts!!
@backgroundnoiselistener3599
@backgroundnoiselistener3599 7 лет назад
best video on L.L great work friend. thanks a lot
@charlesh2215
@charlesh2215 7 лет назад
Thanks for the extrodinary explainations.
@harishbirhman
@harishbirhman 8 лет назад
nice work keep it doing keep helping students.Thanks.
@jithikasagar3575
@jithikasagar3575 6 лет назад
Well explained sir..... thanks a lot😊
@Ajitkumar-kj2gp
@Ajitkumar-kj2gp 5 лет назад
Very helpful lecture. Thanks a lot
@MrPatex21
@MrPatex21 11 лет назад
void Insert(int x){ struct Node* temp = (struct Node*)malloc(sizeof(struct Node)); ...
@praveenkumar.m7949
@praveenkumar.m7949 4 года назад
Error: Node undefined symbol Correct super struct key is not mention in this program
@amazingmanish
@amazingmanish 9 лет назад
Great Work mycodeschool... Keep It Up.
@divaynagar1929
@divaynagar1929 4 года назад
just amazing>>>cant expalin ... so beautiful explaination!!!!!!
@ShekharBhabad
@ShekharBhabad 10 лет назад
keep doing man ......your videos are just awesome.......and much much helpfull
@darknawg63
@darknawg63 8 лет назад
One question. Isn't this program leaking memory? Where in the code should we be deallocating with free?
@ShivamJha00
@ShivamJha00 6 лет назад
Yeah same question
@santhoshbudur9763
@santhoshbudur9763 3 года назад
It's been 8 years. No other video on DSA is better than this. Sad that he stopped uploading videos.
@mrboon8856
@mrboon8856 3 года назад
Hi is no more brother
@caojinguo3043
@caojinguo3043 2 года назад
@@mrboon8856 i'm sorry to hear about that ,what a pity
@paigamehaqq74
@paigamehaqq74 4 года назад
Nicely explained.....😙😚😚😚😚👌
@jimwang4582
@jimwang4582 10 лет назад
Thanks for your tutorial!
@mycodeschool
@mycodeschool 11 лет назад
There are a lot of compilation errors in your code. You are writing "prinf" in your print function instead of "printf" ( t is missing) ... your functions are not returning anything even though their return type is not void. You need to read the compilation errors and try to fix the issues.
@neil9151
@neil9151 8 лет назад
can you provide the actual file of the program for further analysis like a downloadable one? it will be a great add on to your tutorials
@vikash_7541
@vikash_7541 5 лет назад
www.mycodeschool.com/problems/insert-a-node-in-a-linked-list-at-head
@nikitafedotov1651
@nikitafedotov1651 10 лет назад
Amazing! Easy to understand! Thank you very much!
@arush2323
@arush2323 10 лет назад
make some videos on advanced operations on linked lists... like merging,concatination,sorting of linked lists keep doing what you are doing
@daitaswararnavam
@daitaswararnavam 8 лет назад
Hi,head is also of type node,if I am correct, we are just writing head=temp,is the data part of the head null or any garbage?
@sainikhilpalukuri1373
@sainikhilpalukuri1373 5 лет назад
Null
@kunalkumar2717
@kunalkumar2717 4 года назад
bro head is a pointer variable which stores adress. so if we write like head=temp, the adress of temp node would be stored in head node.
@HetviPatel221
@HetviPatel221 8 лет назад
Thanks a lott!! It was really really helpful!! just way better explanation nd short program as compared to the book!!!
@ripon59
@ripon59 6 лет назад
Great .. i love this tutorials too easy..
@marinbeslo7841
@marinbeslo7841 6 лет назад
Very well explained. Thanks a lot :D
@hardikpatel2553
@hardikpatel2553 9 лет назад
Thank you very much for clearing my concept
@shreyasdeo3801
@shreyasdeo3801 6 лет назад
what would have happened if u were not there :p .... u are way better than my tuition teacher and my school computer teacher ....
@wareshakhan5740
@wareshakhan5740 9 лет назад
this tutorial help me alot. thankx for this
@dsc4656
@dsc4656 2 года назад
@mycodeschool in 2:50, we can use for(int i=0,..........) in C too
@harshithamunukutla9081
@harshithamunukutla9081 5 лет назад
sir please do a playlist regarding python programming so it will be helpful for people like me .. as your explanation is very clear it will be understood by everyone so please do a playlist regarding python
@Nothing_New43
@Nothing_New43 11 лет назад
your lectures r very good!!! i loved them all and i am certain that u will also make videos on non linear data structures like tree,graph?! right?!
@mycodeschool
@mycodeschool 10 лет назад
satish sahu We have already published some videos on trees, see our complete series on data structures ru-vid.com/group/PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P
@shubhamambavale9658
@shubhamambavale9658 9 лет назад
i just love this channel... :)
@monicaslv323
@monicaslv323 9 лет назад
In DeV, while programming in C language, for any declaration or manipulation of structures, you should type "struct NameStructure".
@mohitbv2331
@mohitbv2331 8 лет назад
Thank you. However, I am getting an error, when I compile: link.c:13:21: error: ‘Node’ undeclared (first use in this function) struct Node* temp = Node* malloc(sizeof(struct Node));
@ranasikder5497
@ranasikder5497 5 лет назад
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
@maxwelltsangya3810
@maxwelltsangya3810 2 года назад
@@ranasikder5497 I was getting same error but now wonder how his code worked yet mine dodn't.🤔
@phalguniroy5342
@phalguniroy5342 5 лет назад
thank you very much. lots of love.
@RajatJoshiChannel
@RajatJoshiChannel 8 лет назад
few queries... 1. Why do we require head? Can't we store and use the address of 1st node directly? 2. Why does the new node gets added at the beginning of the list?
@advaitharmy
@advaitharmy 7 лет назад
1) To clarify you 1st node does not has address of 1st node. 1st node will have address of 2nd node, 2nd node will have address of 3rd node.......etc. Head has the address of 1st node. S0 if you use address of 1st node you will get elements from node 2 onwards and you are missing 1st node itself. I hope you understood now. 2) Node can be added to any location.
@mycodeschool
@mycodeschool 11 лет назад
In C, say struct Node* wherever you are saying only Node* ... In C++ this will work fine.
@arunabhbora2186
@arunabhbora2186 9 лет назад
thanks man! Now I finally understand it.
@hshw8555
@hshw8555 4 года назад
Thanks a lot my friend you helped me
@maenolis
@maenolis 11 лет назад
There is no need for freeing at the end of the program but someone who is learning now should learn early to free resources for the future. At my university teachers are insisting on that. After all that shows that you know better what you are doing with memory and you have better control. I hadn't googled that before to be honest but this is my humble opinion.
Далее
Linked List in C/C++ - Insert a node at nth position
15:15
Introduction to linked list
17:13
Просмотров 1,6 млн
Скинь той самой ❤️‍🔥
00:15
Просмотров 17 тыс.
Физика пасты Карбонара 🧪🔬
00:57
Китайка и Красивые Глаза😂😆
00:20
Master Pointers in C:  10X Your C Coding!
14:12
Просмотров 318 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 100 тыс.
Linked List - Implementation in C/C++
13:58
Просмотров 1,6 млн
why do void* pointers even exist?
8:17
Просмотров 378 тыс.
CONST in C++
12:54
Просмотров 407 тыс.
Скинь той самой ❤️‍🔥
00:15
Просмотров 17 тыс.