Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Doubly Linked List Delete at Any Position
WhatsApp
Kaushik S
Dec 08
2015
4
k
0
0
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef
struct
node{
int
data;
struct
node* next;
struct
node* prev;
}node;
struct
node* head=NULL;
void
insert(
int
x)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=x;
if
(head==NULL)
{
temp->next=NULL;
head=temp;
temp->prev=head;
}
else
{
head->prev=temp;
temp->next=head;
head=temp;
}
}
void
print()
{
struct
node* temp=head;
while
(temp!=NULL)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
}
void
DeleteAnyValue(
int
x)
{
struct
node* temp=head;
if
(head==NULL)
{
printf(
"No records to delete"
);
}
else
if
(temp->data==x)
{
head=temp->next;
free(temp);
}
else
{
struct
node* temp2=NULL;
temp2=temp->next;
while
(temp->next->data!=x)
{
temp=temp->next;
temp2=temp->next;
}
temp->next=temp2->next;
temp2->prev=temp;
free(temp2);
}
printf(
" After Deletion "
);
print();
}
void
main()
{
insert(5);
insert(2);
insert(3);
insert(7);
print();
DeleteAnyValue(2);
getch();
}
C
Datastructures
Up Next
Doubly Linked List Delete at Any Position