Deletion at given location in the Circular linked list

C function for Deletion at location in Circular linked list


void delete_Location(struct link *node)

{

	int node_no=1,delete_no,flag=0,count;

	node=start->next;

	ptr=start;

	count=i;

	printf("\n Enter position where you want to delete node:");

	scanf("%d",&delete_no);



	while(count)

	{

		if(node_no==delete_no)

		{

			ptr->next=node->next;

			free(node);

			flag=1;

			break;

		}

		else

		{

			ptr=ptr->next;

			node=node->next;

		}

		node_no++;

		count--;

	}

	if(flag==0)

	{

		printf("\n Position not found");

    }

	else

	{

		i--;

	}

}





After Deletion





Deletion at the Location in 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_Location(struct link *node)

{

	int node_no=1,delete_no,flag=0,count;

	node=start->next;

	ptr=start;

	count=i;

	printf("\n Enter position where you want to delete node:");

	scanf("%d",&delete_no);



	while(count)

	{

		if(node_no==delete_no)

		{

			ptr->next=node->next;

			free(node);

			flag=1;

			break;

		}

		else

		{

			ptr=ptr->next;

			node=node->next;

		}

		node_no++;

		count--;

	}

	if(flag==0)

	{

		printf("\n Position not found");

    }

	else

	{

		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_Location(node);

	printf("List Item Are:\n");

	display(node);

	getch();

}




Output