Skip to content

Commit

Permalink
insert at given pos in doublyy linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
WaderManasi committed Sep 16, 2020
1 parent 7ea32ae commit 096f098
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Linked Lists/InsertAtPos_Doublyll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
void addNode(Node *head, int pos, int data)
{
Node* newn= new Node(data);
if(head==NULL) head=newn;
else
{
Node* temp=head;
for(int i=0;i<pos;i++)
temp=temp->next;
if(temp->next==NULL)
{
temp->next=newn;
newn->prev=temp;
}
else
{
temp->next->prev=newn;
newn->next=temp->next;
newn->prev=temp;
temp->next=newn;
}
}
}

0 comments on commit 096f098

Please sign in to comment.