Finding loops/cycles in a linked list

  Рет қаралды 4,394

CodeVault

CodeVault

Күн бұрын

Check out our Discord server: / discord

Пікірлер: 12
@whatever6223
@whatever6223 3 жыл бұрын
Is it really necessary to check whether slow != NULL? Can I simply check for (fast->next != NULL && fast->next->next != NULL) ?
@CodeVault
@CodeVault 3 жыл бұрын
That's true, it's enough to check while(fast != NULL && fast->next != NULL)
@nematkosha6683
@nematkosha6683 3 жыл бұрын
Which site or book would you recommend for linked list structure? i should to study.
@CodeVault
@CodeVault 3 жыл бұрын
I'm really not sure... geeksforgeeks has decent code but it's not the best quality
@nematkosha6683
@nematkosha6683 3 жыл бұрын
@@CodeVault may I have your email this one is my email (nemat.kosha160@gmail.com) send me I email i have some problem to help me
@wassimhaimoudi
@wassimhaimoudi Жыл бұрын
I am having a hard time understanding what would happen if it started looping at node number 3 or 4 basically n>2whereas n is the number of nodes traversed before the first time we encounter a cycle start point. Anyone can help me with that? I tried when n = 3 with 6 nodes total and the first time both pointers intersect at the same location is inside the loop. Basically at node 5. But the problem is the slow pointer didn’t reach the end of the linked list for the first time so we don’t know yet if we are inside a cycle or again since didn’t reach the end from where the cycle loops back which is node 6. Thanks for helping me in advance!
@CodeVault
@CodeVault Жыл бұрын
The fast pointer should always find the slower pointer if a loop exists. It could take more than 1 iteration of the loop for the pointers to coincide
@wassimhaimoudi
@wassimhaimoudi Жыл бұрын
@@CodeVault Thank you for the response! I think I get it now.
@MonkoGames
@MonkoGames 3 жыл бұрын
Im getting a segmentation fault in the while loop
@CodeVault
@CodeVault 3 жыл бұрын
What's the code? And also how do you create the linked list?
@catalinvrabiuta8
@catalinvrabiuta8 2 жыл бұрын
could you put the code from linked lists on a github repository?
@CodeVault
@CodeVault 2 жыл бұрын
The code from all the videos can be found on our website. Here is the link: code-vault.net/lesson/2t4nd0hjh5:1603732280242
Short introduction to doubly linked lists
9:59
CodeVault
Рет қаралды 6 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 15 МЛН
Touching Act of Kindness Brings Hope to the Homeless #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 18 МЛН
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 81 МЛН
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
How to properly deal with dynamically allocated memory
13:44
CodeVault
Рет қаралды 9 М.
Communicating between processes (using pipes) in C
14:00
CodeVault
Рет қаралды 274 М.
Detect loop in linked list(floyd algo / Tortoise and hare algo)
9:29
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 112 М.
Can you add or subtract two pointers?
9:49
CodeVault
Рет қаралды 7 М.
Adding elements to a linked list
18:46
CodeVault
Рет қаралды 39 М.
What are double pointers in C?
14:43
CodeVault
Рет қаралды 43 М.
Les listes chaînées en C - Trier une liste chaînée-
18:15
Programming With HAIRIBI
Рет қаралды 29 М.
Difference between macros and constants in C
12:42
CodeVault
Рет қаралды 11 М.
Reading from text files in C
11:10
CodeVault
Рет қаралды 28 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 15 МЛН