1. ## swap 2 nodes

need to swaping nodes without changing the vlue fields .

my solution

Code:
```void swap(Node *X,Node *Y)
{
Node *prev, *next, *temp;
temp=X;
prev=(X->prev);
next=(X->next);
X=Y;
(X->next)=next;
(X->prev)=prev;
next=(Y->next);
prev=(Y->prev);
Y=temp;
(Y->next)=next;
(Y->prev)=prev;
}```
not working , why ?

TNX ....

2. X=Y;

Because that is just wrong.

3. why ?

4. When you are moving items in a linked list, you have to adjust the VALUES of the pointers in the list. X = Y is just internal to your function.

Since this appears to be a double direction linked list, you'll have to set the next and prev of the one variable to the next and prev of the other while keeping those values. Then, you'll have to set the next of the prev to the Y for X and the prev of the next to the Y for X and the same for Y to X -- Keeping in mind that you'll need to preserve those values prior to changing them in the other.

5. i don`t understand but thank you anyway .

6. All X=Y will do is change the name you have given the objects: the object you used to be calling Y is now also called X (and is still called Y), and the object you used to be calling X is now called --- well, fortunately for you, you kept that in temp! Therefore, your attempt later on to put Y->next and Y->prev into your placeholders is doomed, unless you change them to temp->next and temp->prev.

7. NULL <-(a) <-> (b) <-> (c) <-> (d)->NULL

In the above, if you get X=b and Y=d then you'd have to do something like this:

prev = X.prev
next = X.next
X.prev = y.prev
X.next = y.next
y.prev.next = X
y.next.prev = X

Now for Y

Y.prev = prev
Y.next = next
prev.next = Y
next.prev = Y

8. Originally Posted by Kennedy
NULL <-(a) <-> (b) <-> (c) <-> (d)->NULL

In the above, if you get X=b and Y=d then you'd have to do something like this:

prev = X.prev
next = X.next
X.prev = y.prev
X.next = y.next
y.prev.next = X
y.next.prev = X

Now for Y

Y.prev = prev
Y.next = next
prev.next = Y
next.prev = Y
hmmmm.... sorry for that im bother you , but its not workin too .

9. What do you mean "its not workin too"? I didn't write your program for you, just told you how to do it.

That up there would be pseudo code.

10. i know..

11. Do it on paper first.
No that's no me fobbing you off, I actually seriously recommend that you work it out on paper first because it really does help!