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 Жыл бұрын
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-vl1no2 жыл бұрын
the way you say hello friends to till end of this video is really wonderful
@Anand145273 жыл бұрын
This topic was really tricky and tough to understand but u made it very easy!
@trimotoj7 ай бұрын
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
@icemotion19253 жыл бұрын
Thank you very much sir. You're a very good teacher, the step-by-step drawing really helpmed me.
@digivibe24043 жыл бұрын
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 Жыл бұрын
very nicely explained..Thanks
@anindyasundarhazra25234 жыл бұрын
Nice sirrrrrr. Very good explanation
@raviPrakash-zf2ze4 жыл бұрын
u solved my problem ,explained very well thanks alot🙏🙏🙏
@yx23026 жыл бұрын
Really good class! Make it really clear!
@dhaneshawati7923 Жыл бұрын
Very well explained 🙏🏻
@icseic8914 Жыл бұрын
Very good explanation
@redone7293 жыл бұрын
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.
@sumitbaloda85613 жыл бұрын
yeah! i already checked that
@sorrowdada2 жыл бұрын
that's a swap function. You have to check that in your handler function not in Swap()
@manjunathm76326 жыл бұрын
What if X and Y are adjuscent to each other like a->b or c->d will this logic works
@jyotirmoy_dey6 жыл бұрын
It doesn't work in such case
@Btc2Tao6 жыл бұрын
@vivekanand please reply We need your help!!!
@praveennarvaneni29705 жыл бұрын
//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; }
@marell04514 жыл бұрын
Сижу в 3 часа ночи и делаю по этому видосу лабу для Париматча и попутно смотрю танец сортировок. Всем советую, хороший видос.
@Rusekk-4 жыл бұрын
Ушастым привет!
@ShivaniSingh-mq4pv3 жыл бұрын
Nice explanation
@__noob__coder__3 жыл бұрын
Nicely done. Much Appreciation for you !
@reubenmammen80654 жыл бұрын
Amazing Teaching
@karanchauke Жыл бұрын
Nice 👍 I Understand Thanks 😊
@parampampam44775 жыл бұрын
@ Vivekanand Khyade - Algorithm Every Day In case of (prevY=null) should it be prevX->next=pY ( not prevX->next=prevY)?
@ajayrajsingh79264 жыл бұрын
yes
@niru19314 жыл бұрын
Yes , right
@sayantaniguha85193 жыл бұрын
I think you are right. Where can I have the complete code?
@parampampam44773 жыл бұрын
@@sayantaniguha8519 Unfortunately, I don't have it, but you can code it yourself since the author explained the concept quite good
@sayantaniguha85193 жыл бұрын
@@parampampam4477 ha woh toh sir ka dekh ke ban jayega... Par phir bhi sir ka code samjhe ni hum
@036_ankitjha5 Жыл бұрын
Too good..thnku❤
@niru19314 жыл бұрын
There is a mistake if (pervY==NULL) Than it will be prevX->next=pY not prevX->next=prevY
@sriharshasamayamanthula26924 жыл бұрын
I think head will also be Head=pX right?
@tahaaslam40093 жыл бұрын
@@sriharshasamayamanthula2692 yes
@vaibhavbansal82053 жыл бұрын
Your code is wrong if you want to swap to corresponding nodes then it will not work
@AnkitSaiyan5 жыл бұрын
can we make a program which work for all three cases
@harshitatiwari45313 жыл бұрын
Yes
@manideeptaghosh71582 жыл бұрын
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
@yaredhailu12865 жыл бұрын
dear please help me implementation code for sorting double linked list
@YouTubex08 ай бұрын
just amazing ..
@mahesmahi14945 жыл бұрын
It is not working to swapping of A node and B node so Check it once
@RAJESHKUMAR-eb5bh6 жыл бұрын
if *a* is replaced by *b* ? Or pY == pX.next?
@madanjeetkumar11086 жыл бұрын
sir please upload video on the topic "code explaination of how will you make binary tree using inorder and preorder ,inorder and postorder".
@abilvap56113 жыл бұрын
Thank you very much! everything is perfect
@tilakrajchoubey55342 жыл бұрын
I don't think it would work for adjacent nodes. Correct me someone if I am not.
@icymatress30063 жыл бұрын
does this work for adjacent nodes?
@vrushankdoshi78134 жыл бұрын
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
@gaurimandot57882 жыл бұрын
Exactly
@aryabhatt8896 Жыл бұрын
Just swap x and y before any operation
@fourieruddin871 Жыл бұрын
Dear sir, it doesn't work for adjacent nodes
@shikharsrivastava73123 жыл бұрын
sir but their can be duplicates nodes
@roshanrajkumar78274 жыл бұрын
Sir can u upload a video on sorting a linked list
@holyshit9226 жыл бұрын
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
@supamdeepbains51726 жыл бұрын
I am in the same condition bro
@AboutCodeforcesProblem2 жыл бұрын
Do you have source code?
@sivaganesh44894 жыл бұрын
You're just awesome
@ocochosi4 жыл бұрын
Good job :) thx
@sachinbhalla145 жыл бұрын
sir your code is not working please give source code
@gautamsingh91756 жыл бұрын
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..
@supamdeepbains51726 жыл бұрын
man u teach good but please don't do fake English excent