# Deletion in doubly linked list at beginning

Being the simplest operation, we just need to copy the head pointer to pointer ptr and shift the head pointer to its next, for deletion in the doubly linked list at the beginning.

Now, use the below statements, to make the prev of this new head node point to NULL.

At last, use the free function, to free the pointer ptr.

 free(ptr)

## Algorithm:

• STEP 1:
WRITE UNDERFLOW
GOTO STEP 6
• STEP 2: SET PTR = HEAD
• STEP 4: SET HEAD → PREV = NULL
• STEP 5: FREE PTR
• STEP 6: EXIT

## Example in C:

Output:

 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 1   Enter the element to insert: 2   Node Inserted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 2   Node Deleted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 2   UNDERFLOW 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 1   Enter the element to insert: 1   Node Inserted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 1   Enter the element to insert: 2   Press 0 to insert more elements:   Node Inserted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 2   Node Deleted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 2   Node Deleted Successfully!! 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 2   UNDERFLOW 1.Insert Node 2.Delete node from beginning 3.Exit 4.Enter your choice: 3