Deletion at beginning in the Circular linked list


C function for Deletion at beginning in Circular linked list


void delete_first(struct link *node)

{

	node=start->next;

	ptr=start;

	if(i==0)

	{

		printf("\n List is empty");

		exit(0);

	}

	ptr->next=node->next;

	free(node);

	i--;

}





After Deletion





Deletion at beginning 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_first(struct link *node)

{

	node=start->next;

	ptr=start;

	if(i==0)

	{

		printf("\n List is empty");

		exit(0);

	}

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

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

	display(node);

	getch();

}




Output



Quantitative Aptitude
Reasoning
Programming
Interview