#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
void create(void);
int del(int);
void list(void);

struct node
{
int data;
struct node *ptrnext;
};
struct node *ptrthis,*ptrnew,*ptrfirst;


void main(void)
{
clrscr();
ptrfirst=NULL;
create();
create();
create();
create();
create();
del(5);
del(12);
list();
}

void create()
{
ptrnew=(struct node *)malloc(sizeof(struct node) );
if(ptrthis==NULL)
ptrfirst=ptrthis=ptrnew;
else
{
ptrthis=ptrfirst;
while(ptrthis->ptrnext!=NULL)
ptrthis=ptrthis->ptrnext;
ptrthis->ptrnext=ptrnew;
ptrthis=ptrnew;
}
printf("\nenter number :");
scanf("%d",&ptrthis->data );
ptrthis->ptrnext=NULL;
}

void list()
{
if(ptrfirst==NULL)
{printf("\nno data yet entered");return;}
int n=0;
ptrthis=ptrfirst;
do
{
printf("\nelement no %d :%d",n++,ptrthis->data);
ptrthis=ptrthis->ptrnext;
}
while(ptrthis!=NULL);
}

int del(int data)
{
int value=0;
struct node *ptrbefore;
ptrbefore=NULL;
ptrthis=ptrfirst;
if(ptrthis==NULL)
return value;

do
{
if(ptrthis->data==data)
{
struct node *to_del,*temp;
to_del=ptrthis;
temp=(ptrthis->ptrnext);
if(ptrbefore==NULL)
ptrfirst=ptrthis->ptrnext;
else
{
ptrthis=ptrbefore;                     
ptrthis->ptrnext=temp;                 
}

free(to_del);           
value=1;                               
break;
}

ptrbefore=ptrthis;                             
ptrthis=ptrthis->ptrnext;
}
while(ptrthis!=NULL);
return value;
}
