Iterating over a linked list in C

  Рет қаралды 39,517

CodeVault

CodeVault

Күн бұрын

Пікірлер
@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 5 жыл бұрын
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
@idomark1238
@idomark1238 Жыл бұрын
bro gonna help me pass the next semester thank you sir
@abdulazizalramadan801
@abdulazizalramadan801 Жыл бұрын
Man thank you very much iam struggling in my data structure subject and u helped me alot with this linked list videos
@ThatiMoreira
@ThatiMoreira 10 ай бұрын
Thanks a lot! Your videos are helping me so much!!!
@unexxzzz8186
@unexxzzz8186 Жыл бұрын
Sir, You are a true legend thanks alot
@memenator185
@memenator185 3 жыл бұрын
I learned a lot from your videos, thank you so much :)
@arunkumarsawant6523
@arunkumarsawant6523 2 ай бұрын
While works. But for prints the fist value 15 and comes out.
@benogega2543
@benogega2543 Жыл бұрын
An excellent explanation......
@adirk1259
@adirk1259 3 жыл бұрын
Thanks you master teacher
@alasassi960
@alasassi960 2 жыл бұрын
what a great teacher
@huseynadze7933
@huseynadze7933 Жыл бұрын
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 11 ай бұрын
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 11 ай бұрын
@@CodeVault makes sense, thank you :)
@SphereofTime
@SphereofTime 5 ай бұрын
1:44
@TonimaHaque-x5g
@TonimaHaque-x5g 9 ай бұрын
Just fantastic🌷
@jenny127832
@jenny127832 Жыл бұрын
Very helpful, thank you!
@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!
@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
@flames1087
@flames1087 8 ай бұрын
I Love your Teaching 💖
@arunkumarsawant6523
@arunkumarsawant6523 2 ай бұрын
Got 10 values of int from user in an array by scanf. Called malloc 10 times. Stored pointers in array of pointers. Assigned value and pointer next of struct nodes by dot operator. Values array and pointer array deleted. Every thing is on heap. Is this ok.?
@CodeVault
@CodeVault 2 ай бұрын
That's no longer a linked list, it's just an array with elements that are nodes. If the next pointer points to another place in that array than, yeah, that is still a linked list.
@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
@moneyDev1111
@moneyDev1111 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
@Gowrilekshmi2021
@Gowrilekshmi2021 4 жыл бұрын
Great course
@loukman4191
@loukman4191 2 жыл бұрын
Thank you 💕
@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
@karimdhrif6679
@karimdhrif6679 2 жыл бұрын
i love you man
Adding elements to a linked list
18:46
CodeVault
Рет қаралды 42 М.
Short introduction to linked lists in C
12:32
CodeVault
Рет қаралды 97 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Oh, wait, actually the best Wordle opener is not “crane”…
10:53
Top 7 Data Structures for Interviews Explained SIMPLY
13:02
Codebagel
Рет қаралды 247 М.
I made Tetris in C, this is what I learned
15:15
Austin Larsen
Рет қаралды 25 М.
If you're ambitious but lazy, please watch this video...
12:57
Mark Tilbury
Рет қаралды 451 М.
Understanding and implementing a Linked List in C and Java
18:15
Jacob Sorber
Рет қаралды 251 М.
Programming a multiplayer game from scratch in 7 DAYS
18:28
10 years of coding in 13 minutes
13:28
Joma Tech
Рет қаралды 5 МЛН
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 141 М.
Understanding and implementing a Hash Table (in C)
24:54
Jacob Sorber
Рет қаралды 373 М.
Functional programming - A general introduction
11:47
Daedalus Community
Рет қаралды 121 М.