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
Circular linked list Insert at End
Kaushik S
Nov 23
2015
Code
1.4
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* next;
}node;
struct
node* head;
void
insertCircularAtEnd(
int
x)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=x;
if
(head==NULL)
{
head=temp;
temp->next=head;
}
else
{
struct
node* last=head;
while
(last->next!=head)
{
last=last->next;
}
struct
node* temp2=NULL;
temp2=(node*)malloc(
sizeof
(
struct
node));
temp2->data=x;
last->next=temp2;
temp2->next=head;
}
}
void
print()
{
struct
node* temp=head;
while
(temp->next !=head)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
while
(temp->next ==head)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
}
void
main()
{
insertCircularAtEnd(2);
insertCircularAtEnd(3);
insertCircularAtEnd(4);
insertCircularAtEnd(5);
print();
getch();
}
C
Datastructures
Circular linked list