Circular SLL
Circular SLL
Circular SLL
h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *head;
}
void lastinsert()
{
struct node *newnode,*temp;
int item;
newnode = (struct node *)malloc(sizeof(struct node));
if(newnode == NULL)
{
printf("\nOVERFLOW\n");
}
else
{
printf("\nEnter Data?");
scanf("%d",&item);
newnode->data = item;
if(head == NULL)
{
head = newnode;
newnode -> next = head;
}
else
{
temp = head;
while(temp -> next != head)
{
temp = temp -> next;
}
temp -> next = newnode;
newnode -> next = head;
}
printf("\nnode inserted\n");
}
void begin_delete()
{
struct node *newnode;
if(head == NULL)
{
printf("\nUNDERFLOW");
}
else if(head->next == head)
{
head = NULL;
free(head);
printf("\nnode deleted\n");
}
else
{ newnode = head;
while(newnode -> next != head)
newnode = newnode -> next;
newnode->next = head->next;
free(head);
head = newnode->next;
printf("\nnode deleted\n");
}
}
void last_delete()
{
struct node *newnode, *prenewnode;
if(head==NULL)
{
printf("\nUNDERFLOW");
}
else if (head ->next == head)
{
head = NULL;
free(head);
printf("\nnode deleted\n");
}
else
{
temp = head;
while(temp ->next != head)
{
prenewnode=temp;
temp = temp->next;
}
prenewnode->next = temp -> next;
free(temp);
printf("\nnode deleted\n");
}
}
void search()
{
struct node *temp;
int item,i=0,flag=1;
temp = head;
if(temp == NULL)
{
printf("\nEmpty List\n");
}
else
{
printf("\nEnter item which you want to search?\n");
scanf("%d",&item);
if(head ->data == item)
{
printf("item found at location %d",i+1);
flag=0;
}
else
{
while (temp->next != head)
{
if(temp->data == item)
{
printf("item found at location %d ",i+1);
flag=0;
break;
}
else
{
flag=1;
}
i++;
temp= temp-> next;
}
}
if(flag != 0)
{
printf("Item not found\n");
}
}
}
void display()
{
struct node *temp;
temp=head;
if(head == NULL)
{
printf("\nnothing to print");
}
else
{
printf("\n printing values ... \n");