Deletion at last in the Circular linked list
C function for Deletion at Last Node
void delete_last(struct link *node)
{
int node_no=0,count;
node=start->next;
ptr=start;
count=i;
if(i==0)
{
printf("\n List is empty");
exit(0);
}
while(count)
{
node_no++;
ptr=ptr->next;
node=node->next;
count--;
}
node=start->next;
ptr=start;
while(node_no!=1)
{
node_no--;
ptr=ptr->next;
node=node->next;
}
if(node_no==1)
{
ptr->next=node->next;
free(node);
i--;
}
}

After Deletion

Deletion at the Last in the Circular Linked list
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct link
{
int data;
struct link *next;
};
int i=0;
struct link *node,*start,*ptr,*new1;
void create_link(struct link *node)
{
char ch;
start->next=NULL;
node=start;
fflush(stdin);
printf("\n Enter 'n' for break:");
ch=getchar();
while(ch!='n')
{
node->next=(struct link *)malloc(sizeof(struct link));
node=node->next;
printf("\n Enter data for node:");
scanf("%d",&node->data);
node->next=start;
fflush(stdin);
printf("\n Enter 'n' for break:");
ch=getchar();
i++;
}
}
void delete_last(struct link *node)
{
int node_no=0,count;
node=start->next;
ptr=start;
count=i;
if(i==0)
{
printf("\n List is empty");
exit(0);
}
while(count)
{
node_no++;
ptr=ptr->next;
node=node->next;
count--;
}
node=start->next;
ptr=start;
while(node_no!=1)
{
node_no--;
ptr=ptr->next;
node=node->next;
}
if(node_no==1)
{
ptr->next=node->next;
free(node);
i--;
}
}
void display(struct link *node)
{
int count;
node=start->next;
count=i;
while(count)
{
printf("\t%d",node->data);
node=node->next;
count--;
}
}
void main()
{
char ch;
clrscr();
create_link(node);
delete_last(node);
printf("List Item Are:\n");
display(node);
getch();
}
Output

