TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Doubly Linked List Delete at End
Kaushik S
Dec 08
2015
Code
866
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#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
insertAtEnd(
int
x)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=x;
if
(head==NULL)
{
temp->next=NULL;
head=temp;
}
else
{
struct
node* temp2=head;
while
(temp2->next!=NULL)
{
temp2=temp2->next;
}
temp2->next=temp;
temp->prev=temp2;
temp->next=NULL;
}
}
void
print()
{
struct
node* temp=head;
while
(temp!=NULL)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
}
void
DeleteAtEnd()
{
struct
node* temp=head;
struct
node* temp2=NULL;
while
(temp->next!=NULL)
{
temp2=temp;
temp=temp->next;
}
temp2->next=NULL;
free(temp);
printf(
" After Deletion "
);
print();
}
void
main()
{
insertAtEnd(2);
insertAtEnd(3);
insertAtEnd(6);
insertAtEnd(5);
print();
DeleteAtEnd();
}
C
Datastructures