Read without ads and support Scribd by becoming a Scribd Premium Reader.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>

struct node

{
struct node *llink;
struct node *rlink;
int data;

};
int count(struct node *q)

{
struct node *temp;
temp=q;
int i=0;
while(temp!=null)
{

temp=temp->rlink;
i++;
}return i;
}void addatbeg(struct node **q)

{
struct node *temp;
int data;
temp=*q;
cout<<"\nenter data to be inserted";
cin>>data;
if(temp==null)
{

// cout<<"\nlinked list is empty ";
temp=(struct node *)(malloc(sizeof(struct node)));
temp->data=data;
temp->llink=null;
temp->rlink=null;
*q=temp;

}else

{
struct node *temp1;
temp1=(struct node *)(malloc(sizeof(struct node)));

temp1->data=data;
temp1->llink=null;
temp1->rlink=temp;
temp->llink=temp1;
*q=temp1;

}
}void addatend(struct node **q)
{
struct node *temp;

int data;
cout<<"\nenter data : ";
cin>>data;
temp=*q;
if(temp==null)
{

// cout<<"\nlinked list is empty ";
temp=(struct node *)(malloc(sizeof(struct node)));
temp->data=data;
temp->llink=null;
temp->rlink=null;
*q=temp;
return;

}while(temp->rlink!=null)

temp=temp->rlink;
struct node *temp1;
temp1=(struct node *)(malloc(sizeof(struct node)));;
temp1->data=data;
temp1->llink=temp;
temp1->rlink=null;
temp->rlink=temp1;

}void add(struct node **q)

{
int data,loc;
cout<<"\nenter data n location to insert node : ";
cin>>data>>loc;
if(loc<1||loc>count(*q))
{

cout<<"\nnode doesn't exist!!";
getch();
return;

}if(loc==count(*q))

{
addatend(q);
return;

}if(loc==1)

{
addatbeg(q);
return;

}struct node *temp,*temp1,*temp2;
temp=*q;
while(loc!=1)

{
temp=temp->rlink;
loc--;

}temp2=(struct node *)(malloc(sizeof(struct node)));;

temp1=temp->rlink;
temp2->data=data;
temp2->llink=temp;

temp2->rlink=temp1;
temp->llink=temp2;
temp->rlink=temp2;
temp1->llink=temp2;

}void del(struct node **q)

{
int loc;
cout<<"\nenter node no. to delete : ";
cin>>loc;
if(loc==0||loc>count(*q))
{

cout<<"\nnode doesn't exist!!";
getch();
return;

}struct node *temp;
temp=*q;
if(loc==1)

{
*q=temp->rlink;
cout<<"\ndata deleted : "<<temp->data;
delete(temp);
return;

}if(loc==count(*q))

{
while(loc!=2)
{

temp=temp->rlink;
loc--;
}struct node *temp1;

temp1=temp->rlink;
cout<<"\ndata deleted : "<<temp1->data;
delete(temp1);
temp->rlink=null;
return;

}else

{
while(loc!=2)
{

temp=temp->rlink;
loc--;
}struct node *temp1,*temp2;

temp1=temp->rlink;
temp2=temp1->rlink;
cout<<"\ndata deleted : "<<temp1->data;
delete(temp1);
temp->rlink=temp2;
temp2->llink=temp;

Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more