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 Insert at Front
Kaushik S
Nov 29
2015
Code
1.5
k
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* prev;
struct
node* next;
}node;
struct
node* head=NULL;
void
insert(
int
key)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=key;
if
(head==NULL)
{
temp->next=NULL;
head=temp;
temp->prev=head;
}
else
{
struct
node* temp2=head;
temp->prev=head;
temp->next=head;
temp2->prev=temp->next;
head=temp;
}
}
void
print()
{
struct
node* temp=head;
while
(temp!=NULL)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
}
void
main()
{
insert(1);
insert(2);
insert(3);
insert(4);
insert(5);
print();
getch();
}
C
Datastructures
Doubly Linked List