Program to delete a Node from given List.



#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();
}

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!