|
-
February 11th, 2010, 01:51 AM
#3
Re: Swapping 2 nodes in doubly linked list
 Originally Posted by wael.salman
By the way ,
There are two main cases:
1) The two nodes to swap are next to each other,
2) The two nodes to swap are not next to each other
can we solve them in one solution or every situation should be solved alone??
Thank you
we have to take two steps in common and two steps in specific for each case.
common steps:
1.right pointer of the first node to point where the right pointer of the second node currently pointing.
2.left pointer of the second node to point where the left pointer of the first node is currently pointing.
if the nodes r next to each other then
1.make left pointer of the first node to point the second node.
2.make right pointer of the second node to point the first node.
if the nodes r not next to each other then
1.make left pointer of the first node to point where the left pointer of the second node pointing currently.
2.make right pointer of the second node to point where the right pointer of the first node currently pointing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|