Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions data_structures/doubly_linked_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
void ins_pos() {
int pos;
printf("\nEnter the position where the node should be inserted: ");
scanf("%d", &pos);

if (pos < 1 || pos > count() + 1) {
printf("\nInvalid position!\n");
return;
}

if (pos == 1) {
ins_beg();
return;
}

struct node *newnode = create_node(); // <<< ADD THIS LINE

temp = head;
for (int i = 1; i < pos - 1; i++) {
temp = temp->next;
}

newnode->next = temp->next;
newnode->prev = temp;

if (temp->next != NULL) {
temp->next->prev = newnode;
}

temp->next = newnode;
printf("\n%d is inserted at position %d\n", newnode->data, pos);
}