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

preview_player
Показать описание
We are going to swap two nodes in the linked list by changing their pointers.
Рекомендации по теме
Комментарии
Автор

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.

arugollu
Автор

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!

FranksCreativeCorner
Автор

the way you say hello friends to till end of this video is really wonderful

Rahul-vlno
Автор

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.

digivibe
Автор

This topic was really tricky and tough to understand but u made it very easy!

Anand
Автор

Thank you very much sir. You're a very good teacher, the step-by-step drawing really helpmed me.

icemotion
Автор

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

trimotoj
Автор

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.

redone
Автор

Really good class! Make it really clear!

yx
Автор

u solved my problem, explained very well thanks alot🙏🙏🙏

raviPrakash-zfze
Автор

Nicely done. Much Appreciation for you !

__noob__coder__
Автор

What if X and Y are adjuscent to each other like a->b or c->d will this logic works

manjunathm
Автор

Сижу в 3 часа ночи и делаю по этому видосу лабу для Париматча и попутно смотрю танец сортировок. Всем советую, хороший видос.

marell
Автор

@
Vivekanand Khyade - Algorithm Every Day

In case of (prevY=null) should it be prevX->next=pY ( not prevX->next=prevY)?

parampampam
Автор

Your code is wrong if you want to swap to corresponding nodes then it will not work

vaibhavbansal
Автор

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

manideeptaghosh
Автор

There is a mistake if (pervY==NULL) Than it will be prevX->next=pY not prevX->next=prevY

niru
Автор

Thank you very much! everything is perfect

abilvap
Автор

can we make a program which work for all three cases

AnkitSaiyan
Автор

I don't think it would work for adjacent nodes. Correct me someone if I am not.

tilakrajchoubey