#include<iostream.h>
#include<stdio.h>
#include<conio.h>
struct adjnode
{
char dest;
adjnode *link;
};
struct node
{
char data;
node *next;
adjnode *adj;
};
node *first,*last,*start;
void enteradj(node* ptr)
{ int nadj;
cout<<” no of adjacent node present??”;
cin>>nadj;
if(nadj>0)
{
adjnode *beg,*end;
beg=new(adjnode);
ptr->adj=beg;
cout<<“enter the first adjacent member/destination”;
cin>>beg->dest;
beg->link=NULL;
for(int a=1;a<nadj;a++)
{
end=new(adjnode);
cout<<“enter destination”;
cin>>end->dest;
fflush(stdin);
end->link=NULL;
beg->link=end;
beg=end;
}
}
}
void findnode()
{ int flag=0;
char ch;
node *ptr;
ptr=start;
cout<<“enter the node to be found”;
cin>>ch;
fflush(stdin);
while(ptr!=NULL)
{
if(ch==ptr->data)
{
flag=1;
break;
}
ptr=ptr->next;
}
if(flag==1)
{
cout<<“yes the item is present”;
}
else{
cout<<“unsuccessful search”;
}
}
void insertnode()
{
node *ptr;
ptr=new(node);
cout<<“enter data”;
cin>>ptr->data;
ptr->next=NULL;
last->next=ptr;
last=ptr;
enteradj(ptr);
}
void deletenode()
{ node *ptr,*save;
char dlt;
int flag=0;
cout<<“enter data to be deleted”;
cin>>dlt;
ptr=start;
if(dlt==ptr->data)
{
start=start->next;
delete ptr;
}
else
{ptr=start->next;
save=start;
while(ptr!=NULL)
{
if(ptr->data==dlt)
{flag=1;
save->next=ptr->next;
delete ptr;
}
else
{
save=ptr;
ptr=ptr->next;
}
}
}
if(flag==0)
{
cout<<“unsuccessful”;
}
}
int main()
{
int n;
cout<<“enter n”;
cin>>n;
first=new(node);
cout<<“enter the first data”;
cin>>first->data;
first->next=NULL;
start=first;
fflush(stdin);
enteradj(first);
for(int b=1;b<n;b++)
{
last=new(node);
cout<<“enter the data of node”;
cin>>last->data;
fflush(stdin);
enteradj(last);
last->next=NULL;
first->next=last;
first=last;
}
int choice;
do
{
cout<<” enter 1 to insert a node”;
cout<<“\n 2 to delete a node containing particular data”;
cout<<“\n 3 to find a node”;
cout<<“\n 4 to exit”;
cin>>choice;
switch(choice)
{
case 1: insertnode();
break;
case 2: deletenode();
break;
case 3: findnode();
break;
}
}while(choice!=4);
getch();
return 0;
}