Iterating over a linked list in C

  Рет қаралды 35,755

CodeVault

CodeVault

4 жыл бұрын

Check out our Discord server: / discord

Пікірлер: 35
@n33to
@n33to 3 жыл бұрын
Sir, you are an excellent teacher and I thank you for your hard work.
@anabrr
@anabrr 2 жыл бұрын
You are incredible, I don't know what would I do without you. Thank you so much!!
@ayushmanpraxri7063
@ayushmanpraxri7063 4 жыл бұрын
Sir you're awesome thank you so much Makin these videos free you've cleared all of my doubts please keep making more data structures videos thanks again
@memenator185
@memenator185 3 жыл бұрын
I learned a lot from your videos, thank you so much :)
@unexxzzz8186
@unexxzzz8186 Жыл бұрын
Sir, You are a true legend thanks alot
@ThatiMoreira
@ThatiMoreira 4 ай бұрын
Thanks a lot! Your videos are helping me so much!!!
@abdulazizalramadan801
@abdulazizalramadan801 9 ай бұрын
Man thank you very much iam struggling in my data structure subject and u helped me alot with this linked list videos
@idomark1238
@idomark1238 Жыл бұрын
bro gonna help me pass the next semester thank you sir
@benogega2543
@benogega2543 Жыл бұрын
An excellent explanation......
@jenny127832
@jenny127832 Жыл бұрын
Very helpful, thank you!
@user-jv7of9tp6g
@user-jv7of9tp6g 4 ай бұрын
Just fantastic🌷
@adirk1259
@adirk1259 2 жыл бұрын
Thanks you master teacher
@flames1087
@flames1087 3 ай бұрын
I Love your Teaching 💖
@alasassi960
@alasassi960 2 жыл бұрын
what a great teacher
@loukman4191
@loukman4191 Жыл бұрын
Thank you 💕
@vambans2412
@vambans2412 4 жыл бұрын
Great course
@PachucoDesigns
@PachucoDesigns 4 жыл бұрын
Can you explain to me the difference between using arrow and using dot when referencing an attribute of a node? Because curr->x and curr.x seem to do the same thing.
@CodeVault
@CodeVault 4 жыл бұрын
curr.x; // Gets the x property from curr (where curr is a struct type) curr->x; // Gets the x property from curr (where curr is of pointer to struct type) Essentially, curr->x is a shorthand for (*curr).x, dereferencing curr then accessing the x property
@alexneagoe5258
@alexneagoe5258 2 жыл бұрын
I think this was very good, thank you for this, it was an instant subscribe! I have a question. could the loop that you have used for printing, be modified in order to be used to with free? I could make the while loop work by swaping a temp value assigned with the next node with the current node value after free and using the current node !=NULL in the condition, but with for loop it wouldn't work, I would get funny valgrind errors (either would free the heap but with stack errors, or would memory leak the heap).
@CodeVault
@CodeVault 2 жыл бұрын
Cred ca asta ar trebui sa functioneze, am scos incrementul din for loop ca trebuie sa ai o variabila auxiliara dupa cum ai zis: for (Node* curr = &root; curr != NULL;) { Node* aux = curr->next; free(curr); curr = aux; } I guess, daca chiar vrei incrementul poti sa faci asta: Node* aux; for (Node* curr = &root; curr != NULL; curr = aux) { Node* aux = curr->next; free(curr); }
@alexneagoe5258
@alexneagoe5258 2 жыл бұрын
​@@CodeVault salutare și mulțumesc de replyul foarte rapid, nu mi-am dat seama prima oară de unde ești. Am încercat ambele variante și au mers fără probleme (nu știam că pot face asta, sunt foarte bucuros că for loop poate fi manipulat cu un increment oarecum fake) // for loop without increment for(node *tmp = list; tmp != NULL;) { tmp = list->next; free(list); list = tmp; } // for loop with increment for(node *tmp = list; tmp != NULL; list = tmp) { tmp = list->next; free(list); } valgrind îmi arată că e totul ok!! Mulțumesc încă o dată, am învățat ceva nou și voi avea grijă să mă uit la celelalte materiale pe care le ai pentru C. Sunt la început deocamdată :)
@CodeVault
@CodeVault 2 жыл бұрын
Mult succes in continuare!
@karimdhrif6679
@karimdhrif6679 2 жыл бұрын
i love you man
@fadieid5638
@fadieid5638 Жыл бұрын
Thank you for this amazing explanation. Just wondering, shouldn't we cast the malloc(sizeof(Node)) into a pointer to Node? malloc return void* type and we are assigning it to Node*
@CodeVault
@CodeVault Жыл бұрын
I did some research on this and, in C++ it's recommended you cast the result of malloc, in C it is not
@fadieid5638
@fadieid5638 Жыл бұрын
Thank you, Intellisense on VS code was turning on this red squiggly line under the malloc signaling type mismatch
@huseynadze7933
@huseynadze7933 7 ай бұрын
Hello, is stopping the iteration with ==NULL always safe? can't we mark the last one with "tail pointer" while adjusting to our linked list, and then while iterating we can check if the the current is equal to "tail"?
@CodeVault
@CodeVault 6 ай бұрын
It's not quite safe if you end up with cycles in the linked list (it can iterate forever)... The solution you wrote wouldn't be much safer since the cycle could end up not including the tail node thus iterating forever again
@huseynadze7933
@huseynadze7933 6 ай бұрын
@@CodeVault makes sense, thank you :)
@C0D3O
@C0D3O 3 жыл бұрын
thank you:) but do you know how to iterate elements in a vue recycler scroller list??????:)
@CodeVault
@CodeVault 3 жыл бұрын
I don't know much about vue
@forheuristiclifeksh7836
@forheuristiclifeksh7836 19 күн бұрын
1:44
@mongraal2272
@mongraal2272 2 жыл бұрын
but root should be on heap,not on stack
@CodeVault
@CodeVault 2 жыл бұрын
In our case it's on the stack because of the definition (Node root). But you can define it on the heap if you want
Adding elements to a linked list
18:46
CodeVault
Рет қаралды 39 М.
Short introduction to linked lists in C
12:32
CodeVault
Рет қаралды 87 М.
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 25 МЛН
What is the Difference Between a Pointer and a Reference C++
7:58
Paul Programming
Рет қаралды 427 М.
How to Implement a Tree in C
14:39
Jacob Sorber
Рет қаралды 93 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 6 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Bit Fields in C. What are they, and how do I use them?
13:26
Jacob Sorber
Рет қаралды 80 М.
Sorted linked list
18:11
CodeVault
Рет қаралды 16 М.
the cleanest feature in C that you've probably never heard of
8:13
Low Level Learning
Рет қаралды 132 М.
Learn Linked Lists in 13 minutes 🔗
13:24
Bro Code
Рет қаралды 275 М.
10 FORBIDDEN Sorting Algorithms
9:41
Ardens
Рет қаралды 831 М.
Removing an element from a linked list
13:15
CodeVault
Рет қаралды 14 М.