Swap nodes in a linked list without swapping data (Very Easy Explanantion)

  Рет қаралды 56,518

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер: 70
@arugollu
@arugollu 4 жыл бұрын
I was struggling to understand swapping logic today. Your explanation and drawing helped me understand. You do not assume anything and you explain from scratch. Thanks a lot for your videos. You are one of my teachers to master datastructures.
@FranksCreativeCorner
@FranksCreativeCorner Жыл бұрын
After a year and a half of learning and practicing pointers and linked lists, one would expect to be able to seamlessly understand these kinds of things, but to my surprise it's still really hard to grasp. Pointers are confusing alone, but when swapping nodes, it's another story. And it can get even crazier: just imagine doing this on doubly linked lists... Or in circular lists! OR IN TREES!!! Anyways, I needed this to make a sorting function for linked lists, but didn't get it right until I saw this video. You kept all the details and mantained a slow pace in your explanation, just what I needed. Many teachers could learn from this... Thank you very much sir!
@Rahul-vl1no
@Rahul-vl1no 2 жыл бұрын
the way you say hello friends to till end of this video is really wonderful
@Anand14527
@Anand14527 3 жыл бұрын
This topic was really tricky and tough to understand but u made it very easy!
@trimotoj
@trimotoj 7 ай бұрын
For adjacent nodes the swapping logic is slightly different: temp = pY -> next pY -> next = pX (without next) pX -> next = temp prevX -> next = pY You don't need to modify prevY
@icemotion1925
@icemotion1925 3 жыл бұрын
Thank you very much sir. You're a very good teacher, the step-by-step drawing really helpmed me.
@digivibe2404
@digivibe2404 3 жыл бұрын
I really enjoy your way of explaining the concepts of swapping nodes in. I have subscribed and will be watching all your lectures. Thank you sir.
@hrutikmore9828
@hrutikmore9828 Жыл бұрын
very nicely explained..Thanks
@anindyasundarhazra2523
@anindyasundarhazra2523 4 жыл бұрын
Nice sirrrrrr. Very good explanation
@raviPrakash-zf2ze
@raviPrakash-zf2ze 4 жыл бұрын
u solved my problem ,explained very well thanks alot🙏🙏🙏
@yx2302
@yx2302 6 жыл бұрын
Really good class! Make it really clear!
@dhaneshawati7923
@dhaneshawati7923 Жыл бұрын
Very well explained 🙏🏻
@icseic8914
@icseic8914 Жыл бұрын
Very good explanation
@redone729
@redone729 3 жыл бұрын
This is the best explanation I have seen. But this solution will not work if Y > X or if the two nodes is next to each other.
@sumitbaloda8561
@sumitbaloda8561 3 жыл бұрын
yeah! i already checked that
@sorrowdada
@sorrowdada 2 жыл бұрын
that's a swap function. You have to check that in your handler function not in Swap()
@manjunathm7632
@manjunathm7632 6 жыл бұрын
What if X and Y are adjuscent to each other like a->b or c->d will this logic works
@jyotirmoy_dey
@jyotirmoy_dey 6 жыл бұрын
It doesn't work in such case
@Btc2Tao
@Btc2Tao 6 жыл бұрын
@vivekanand please reply We need your help!!!
@praveennarvaneni2970
@praveennarvaneni2970 5 жыл бұрын
//This is the code which can handle two adjacent nodes either but the function assumes that first node occurs first and second node there after struct node *Swapnodes(struct node *head, struct node *first, struct node *second) { if (head == NULL) { //printf(" You are given a null header to swap nodes "); return NULL; } if (first == second) return head; //printf(" Can u see us I am head:%u I am first first:%u, I am second:%u ", head, head, second); struct node *temp; struct node *prev1 = NULL; struct node *prev2 = NULL; int found = 0, flag = 0; if (head == first) found = 1; for (temp = head; temp != NULL && !found; temp = temp->next) { printf(" I am searching second, temp is :%u", temp); if (temp->next == first) { found = 1; prev1 = temp; } } if (!found) { printf(" First not found "); return NULL; } found = 0; for (temp = head; temp != NULL; temp = temp->next) { printf(" I am searching second, temp is :%u", temp); if (temp->next == second) { found = 1; prev2 = temp; break; } } if (!found) { printf(" Second is not found "); return NULL; } if (!prev2) { printf("Unfortunately I found prev2 as null"); return NULL; } if (prev2 == first) { flag = 1; } if (prev1 != NULL) { temp = second->next; prev1->next = second; if (flag) { second->next = first; } else { second->next = first->next; prev2->next = first; } first->next = temp; return head; } temp = second->next; if (flag) { second->next = first; } else { second->next = first->next; prev2->next = first; } first->next = temp; return second; }
@marell0451
@marell0451 4 жыл бұрын
Сижу в 3 часа ночи и делаю по этому видосу лабу для Париматча и попутно смотрю танец сортировок. Всем советую, хороший видос.
@Rusekk-
@Rusekk- 4 жыл бұрын
Ушастым привет!
@ShivaniSingh-mq4pv
@ShivaniSingh-mq4pv 3 жыл бұрын
Nice explanation
@__noob__coder__
@__noob__coder__ 3 жыл бұрын
Nicely done. Much Appreciation for you !
@reubenmammen8065
@reubenmammen8065 4 жыл бұрын
Amazing Teaching
@karanchauke
@karanchauke Жыл бұрын
Nice 👍 I Understand Thanks 😊
@parampampam4477
@parampampam4477 5 жыл бұрын
@ Vivekanand Khyade - Algorithm Every Day In case of (prevY=null) should it be prevX->next=pY ( not prevX->next=prevY)?
@ajayrajsingh7926
@ajayrajsingh7926 4 жыл бұрын
yes
@niru1931
@niru1931 4 жыл бұрын
Yes , right
@sayantaniguha8519
@sayantaniguha8519 3 жыл бұрын
I think you are right. Where can I have the complete code?
@parampampam4477
@parampampam4477 3 жыл бұрын
@@sayantaniguha8519 Unfortunately, I don't have it, but you can code it yourself since the author explained the concept quite good
@sayantaniguha8519
@sayantaniguha8519 3 жыл бұрын
@@parampampam4477 ha woh toh sir ka dekh ke ban jayega... Par phir bhi sir ka code samjhe ni hum
@036_ankitjha5
@036_ankitjha5 Жыл бұрын
Too good..thnku❤
@niru1931
@niru1931 4 жыл бұрын
There is a mistake if (pervY==NULL) Than it will be prevX->next=pY not prevX->next=prevY
@sriharshasamayamanthula2692
@sriharshasamayamanthula2692 4 жыл бұрын
I think head will also be Head=pX right?
@tahaaslam4009
@tahaaslam4009 3 жыл бұрын
@@sriharshasamayamanthula2692 yes
@vaibhavbansal8205
@vaibhavbansal8205 3 жыл бұрын
Your code is wrong if you want to swap to corresponding nodes then it will not work
@AnkitSaiyan
@AnkitSaiyan 5 жыл бұрын
can we make a program which work for all three cases
@harshitatiwari4531
@harshitatiwari4531 3 жыл бұрын
Yes
@manideeptaghosh7158
@manideeptaghosh7158 2 жыл бұрын
there is a problem . you have told the search function is a void type so it will return nothing.so if it returns nothing then how will those pointers prevX,prevY,pX,pY will work in the swap function. please explain
@yaredhailu1286
@yaredhailu1286 5 жыл бұрын
dear please help me implementation code for sorting double linked list
@YouTubex0
@YouTubex0 8 ай бұрын
just amazing ..
@mahesmahi1494
@mahesmahi1494 5 жыл бұрын
It is not working to swapping of A node and B node so Check it once
@RAJESHKUMAR-eb5bh
@RAJESHKUMAR-eb5bh 6 жыл бұрын
if *a* is replaced by *b* ? Or pY == pX.next?
@madanjeetkumar1108
@madanjeetkumar1108 6 жыл бұрын
sir please upload video on the topic "code explaination of how will you make binary tree using inorder and preorder ,inorder and postorder".
@abilvap5611
@abilvap5611 3 жыл бұрын
Thank you very much! everything is perfect
@tilakrajchoubey5534
@tilakrajchoubey5534 2 жыл бұрын
I don't think it would work for adjacent nodes. Correct me someone if I am not.
@icymatress3006
@icymatress3006 3 жыл бұрын
does this work for adjacent nodes?
@vrushankdoshi7813
@vrushankdoshi7813 4 жыл бұрын
Nice explanation.. but the solution will not work if we have a linked list as 1-2-3-4-null and your x = 4 and y = 1 instead of x= 1 and y =4
@gaurimandot5788
@gaurimandot5788 2 жыл бұрын
Exactly
@aryabhatt8896
@aryabhatt8896 Жыл бұрын
Just swap x and y before any operation
@fourieruddin871
@fourieruddin871 Жыл бұрын
Dear sir, it doesn't work for adjacent nodes
@shikharsrivastava7312
@shikharsrivastava7312 3 жыл бұрын
sir but their can be duplicates nodes
@roshanrajkumar7827
@roshanrajkumar7827 4 жыл бұрын
Sir can u upload a video on sorting a linked list
@holyshit922
@holyshit922 6 жыл бұрын
Suppose we have given pointers to the nodes we want to swap and our linked list is doubly linked list How would our code look like
@supamdeepbains5172
@supamdeepbains5172 6 жыл бұрын
I am in the same condition bro
@AboutCodeforcesProblem
@AboutCodeforcesProblem 2 жыл бұрын
Do you have source code?
@sivaganesh4489
@sivaganesh4489 4 жыл бұрын
You're just awesome
@ocochosi
@ocochosi 4 жыл бұрын
Good job :) thx
@sachinbhalla14
@sachinbhalla14 5 жыл бұрын
sir your code is not working please give source code
@gautamsingh9175
@gautamsingh9175 6 жыл бұрын
sir, if you want to increase your viewer you must add some background sound in video cause, it will help to motivate while we watch your videos ....i think you apply my suggestion in you'r videos thank for you'r video it help a lot..
@supamdeepbains5172
@supamdeepbains5172 6 жыл бұрын
man u teach good but please don't do fake English excent
@satyakighosh4226
@satyakighosh4226 6 жыл бұрын
cool english
@tommystephen9146
@tommystephen9146 3 жыл бұрын
Supamdeep Bains, What is excent?
@tcsInfosysWipro
@tcsInfosysWipro Жыл бұрын
@@tommystephen9146 dammn !
@ashifkasala6897
@ashifkasala6897 6 жыл бұрын
Jus to remember me i disliked video.Sorry
Swap/Reverse nodes in a group of size = k in a linked list
14:46
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 36 М.
Swap nodes pairwise in Linked List (nodes in pairs)
15:14
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 44 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 15 МЛН
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 5 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 38 МЛН
Detect loop in linked list(floyd algo / Tortoise and hare algo)
9:29
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 112 М.
Data Structures in Python: Singly Linked Lists -- Node Swap
16:07
LucidProgramming
Рет қаралды 31 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 23 МЛН
Circular Linked List in Data Structures (with Code)
21:46
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 52 М.
Add two numbers represented by linked lists
16:26
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 65 М.
Reverse a Doubly Linked List in C
12:12
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 48 М.
Merge two sorted Linked Lists to form a new Sorted Linked List
13:59
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 173 М.
Swap nodes in Linked List without Copy | Programming Interview | C++
20:48
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 15 МЛН