write a function to delete the largest item from a sorted (asc) Circular Linked List (a CLLNode is list where the last element is pointing to head).
C code is given below for more understanding with output:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct A
{
int value;
struct A *next;
}NODE;
NODE *head;
int main()
{
//create 4 node circular link list:
head=(NODE*)malloc(sizeof(NODE));
scanf("%d",&head->value);
head->next=NULL;
NODE *ptr=head ,*temp;
int i;
for(i=1;i<=3;i++)
{
temp=(NODE*)malloc(sizeof(NODE));
scanf("%d",&temp->value);
temp->next=NULL;
head->next=temp;
head=temp;
}
head->next=ptr;
//a circular list created and head denote to last node:
//Now Delete largest element:
//circular link list before deletion:
printf("Circular link list before deletion\n");
print(head,ptr);
NODE *head1=head;
while(head1->next!=head)
head1=head1->next;
head1->next=head->next;
free(head);
head=head1;
//circular link list after deletion:
printf("\nCircular link list after deletion:\n");
print(head,ptr);
return 0;
}
int print(NODE *ptr , NODE *head)
{
while(head!=ptr)
{
printf("%d -> ",head->value);
head=head->next;
}
printf("%d",ptr->value);
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.