void insertAtPosition(node *&head, node *&tail, int position, int d) {
// insert at start
if (position == 1) {
insertAtHead(head, tail, d);
return;
}
node *temp = new node(d);
node *curr = head;
int cnt = 1;
while (cnt < position - 1) {
curr = curr->next;
cnt++;
}
// insert at last
if (curr->next == NULL) {
insertAtTail(tail, head, d);
return;
} else {
temp->next = curr->next;
curr->next = temp;
temp->prev = curr;
curr->next->prev = temp;
}
}