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
Delete a Node at the Front of Circular Linked List
Kaushik S
Nov 24
2015
Code
978
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
insertAtFront(
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;
temp2->next=head;
last->next=temp2;
}
}
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
DeleteAtFront(
int
x)
{
struct
node* temp=head;
if
(head==NULL)
{
printf(
"Cannot be deleted"
);
}
else
{
struct
node* temp2=NULL;
temp2=temp->next;
temp->next=temp2->next;
temp->data=temp2->data;
free(temp2);
}
printf(
":After Deletion:"
);
print();
}
void
main()
{
insertAtFront(2);
insertAtFront(3);
insertAtFront(4);
insertAtFront(5);
print();
DeleteAtFront(2);
getch();
}
C
Datastructures
Front of Circular Linked List