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 Insert At End
WhatsApp
Kaushik S
Dec 08
2015
968
0
0
#include<stdio.h>
#include<stdlib.h>
#include<conio.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;
temp->prev=head;
}
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
main()
{
insertAtEnd(2);
insertAtEnd(3);
insertAtEnd(6);
insertAtEnd(4);
print();
getch();
}
C
Datastructures
Linked List
Up Next
Doubly Linked List Insert At End