Welcome To Uday Satya Blog

17 . DELETE BEGINING LL



/* ****************************************************
      17 . TO DELETE AN ELEMENT AT THE BEGINNING .
     ************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include<*malloc.h>
void main()
{
struct link
{
int info;
struct link*next;
};
struct link*head,*cur,*temp;
char ch='y';
clrscr();
head=(struct link*)malloc(sizeof(struct link));
printf("\n enter head element : ");
scanf("%d",&head->info);
head->next=NULL;
cur=head;
do
{
temp=(struct link*)malloc(sizeof(struct link));
printf("\n\n enter number to be inserted : ");
scanf("%d",&temp->info);
printf("\n\n do you want to insert more (yes,no) : ");
ch=getch();
temp->next=cur;
cur=temp;
}while(ch=='y');
head=cur;
printf("\n\n the elements inserted  before deletion : ");
while(cur!=NULL)
{
printf("%d\t",cur->info);
cur=cur->next;
}
printf("\n\n elements after deletion : ");
cur=head;
temp=cur->next;
free(cur);
cur=temp;
while(cur!=NULL)
{
printf("%d\t",cur->info);
cur=cur->next;
}
getch();
}

output

 enter head element : 1

 enter number to be inserted : 2

 do you want to insert more (yes,no) :

 the elements inserted  before deletion : 2     1

 elements after deletion : 1

0 comments:

Post a Comment