Skip to content

Commit

Permalink
Merge pull request #4 from Divya19gupta/patch-4
Browse files Browse the repository at this point in the history
Create Swap nodes using dll
  • Loading branch information
alphavoid authored Oct 8, 2020
2 parents 198b3e9 + f6f3021 commit 673accd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Swap nodes using dll
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
void swapNodes(int x, int y)
{
if(x==y)
return;
LinkList prevx=null, currx=head;
while(currx!=null&&currx.data!=x)
{
prevx=currx;
currx=currx.next;
}
LinkList prevy=null, curry=head;
while(curry!=null&&curry.data!=y)
{
prevy=curry;
curry=curry.next;
}
if(currx==null||curry==null)
return;
if(prevx!=null)
prevx.next=curry;
else
head=curry;
if(prevy!=null)
prevy.next=currx;
else
head=currx;

LinkList temp=currx.next;
currx.next=curry.next;
curry.next=temp;

0 comments on commit 673accd

Please sign in to comment.