#include
#include
struct node
{
int info;
node *link;
};
class linklist
{
private:
node *start;
public:
linklist()
{
start=NULL;
}
void addnode(int i)
{
node *newlink=new node;
newlink->info=i;
newlink->link=start;
start=newlink;
}
void display(int no);
void search(int item);
void insloc(int item,int loc);
int find(int item);
void del(int loc,int locp);
};
void linklist::display(int no)
{
int i=1;
int n=no;
node *move=start;
node *temp;
cout<<"node no\t"<<"node info\t\t"<<"location\t\t"<<"link\n";
while(move)
{
temp=move;
move=move->link;
if(i==n)
{
cout<<<"\t\t"<info<<"\t\t"<<<"\t\t"<<"null\n";
i++;
break; } cout<<<"\t\t"<info<<"\t\t"<<<"\t\t"<<ptr->info)
{
ptr=ptr->link;
}
else if(item==ptr->info)
{
cout<<"Element"<- <<"found at\t"<<<"element not found";
return;
}
}
cout<<"element not found";
}
void linklist :: insloc(int item , int loc)
{
int i=1;
node *newlink=new node;
newlink->info=item;
if(loc==0)
{
newlink->link=start;
start=newlink;
return;
}
node *ptr=start;
while(ptr)
{
if(i==loc)
{
newlink->link=ptr->link;
ptr->link=newlink;
return;
}
ptr=ptr->link;
i++;
}
}
int linklist :: find (int item)
{
node *ptr=start;
int loc;
int save=1;
if(start==NULL)
{
loc=0;
return loc;
}
if(iteminfo)
{
loc=0;
return loc;
}
ptr=ptr->link;
while(ptr)
{
if(iteminfo)
{
loc=save;
return loc;
}
save++;
ptr=ptr->link;
}
loc=save;
return loc;
}
void linklist :: del(int loc,int locp)
{
node *ptrloc=start;
node *ptrlocp;
int i=1;
if(locp==0)
{
start=start->link;
}
else
{
while(ptrloc)
{
ptrlocp=ptrloc;
ptrloc=ptrloc->link;
if(i==locp)
{
ptrlocp->link=ptrloc->link;
return;
}
i++;
}
}
}
void main()
{
int n,i,a[10],item,loc,locp;
linklist link;
cout<<"enter no. of nodes\n"; cin>>n;
cout<<"enter value\n"; for(i=0;i>a[i];
link.addnode(a[i]);
}
link. display(n);
cout<<"enter of search"; cin>>item;
cout<<"enter location to delete"; cin>>loc;
locp=loc-1;
link.del(loc,locp);
n=n-1;
link.display(n);
getch();
}
No comments:
Post a Comment