hello
the problem is like this i have a linked list, i need to delete the nods that have info 'a'
the program is this one
i want u to look at the verificare function and after the verification if the first node is a...Code:#include <iostream>
using namespace std;
struct nod
{
char info;
nod *urm;//urm is pointer to the next node
};nod *prim,*ultim;//prim remembers the first node, ultim remembers the
last one
void adaugare (char a);
void verificare();
void primnod();
int main()
{
int n;//size of list
char k; //info
cout<<"cate elemente vrei sa adaugi in lista? ";
cin>>n;
primnod();//the function that declares the frist node
for(int i=2;i<=n;i++)
{
cout<<"dati valoarea pt elementul al"<<i<<"-lea ";
cin>>k;
adaugare(k);
}
nod *x= new nod;
verificare();
x=prim;
for(x=prim;x<=ultim;x=x->urm)
{
cout<<x->info<<" ";
if(x->urm==NULL)
{cout<<endl;
break;
}
}
cout<<"merge";
return 0;
}
void primnod()
{
nod *p=new nod;
cout<<"introduceti valoarea primului nod ";
cin>>p->info;
prim=ultim=p;
p->urm=NULL;
}
void adaugare(char a)
{
nod *p= new nod;
p->info= a;
ultim->urm=p;
ultim=p;
p->urm=NULL;
}
void verificare()
{ nod *x=new nod;
nod *q=new nod;
x=prim;
q=prim;
while(prim->info=='a')
{
nod *p;
p=prim;
prim=p->urm;
delete p;
}
while(q->urm!=NULL)
{
if(q->urm->info=='a')
{
nod *i=new nod;
i=q->urm;
while(i->info='a')
{
nod *t= new nod;
t=i;
i=t->urm;
delete t;
}
q->urm=i->urm;
delete i;
}
q->urm=q->urm->urm;
}
}
exactly this part
i thinked like this, i positioned with q before the node with 'a' info i created a pointer to q->urm then i entered in a while loop and created a pointer to start delete the nodes with a...if they are more in line...Code:while(q->urm!=NULL)
{
if(q->urm->info=='a')
{
nod *i=new nod;
i=q->urm;
while(i->info='a')
{
nod *t= new nod;
t=i;
i=t->urm;
delete t;
}
q->urm=i->urm;
delete i;
}
q->urm=q->urm->urm;
}
please tell me what is wrong, i'm sorry for my bad format, this is my first post on this forum...
//best regards