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 Delete at Last
Kaushik S
Nov 24
2015
Code
1.3
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
insertAtEnd(
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;
head=temp2;
last->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;
}
}
deleteAtEnd()
{
struct
node* temp=head;
if
(temp==NULL)
{
printf(
"No items to delete"
);
}
else
{
struct
node* last=head;
struct
node* temp2=NULL;
while
(last->next!=head)
{
temp2=last;
last=last->next;
}
temp2->next=last->next;
//last=head;
free(last);
}
print();
}
void
main()
{
insertAtEnd(2);
insertAtEnd(4);
insertAtEnd(6);
insertAtEnd(8);
print();
deleteAtEnd();
getch();
}
C
Datastructures
Circular Linked List